Objective-c Chapter 1-2 Hello World

Source: Internet
Author: User
Tags at sign






Objective-c Chapter 1 Hello World



1.1






1.2.On The Welcome screen, click "Create a new Xcode project" (see Figure 2-1), or just choose
File->new->new Project.












1.3. Write the following code in main





#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        // insert code here...

        NSLog(@"Hello, World!");

    }

    return 0;

}





Build and run the program by clicking the Run button or pressing? R.



Open The Xcode console window (by selecting View Debug Area Activate console or pressing?? C), which displays your program ' s output,















Now let's pull it apart and see how it works.






1.4.1



#import



#import <Foundation/Foundation.h>



#import guarantees that a header file would be included only once, no matter what many times the #import directive is actual Ly seen for that file.



#import guarantee that the header file can only be included once, no matter how many times the #import introduces this file.






1.4.2



Introducing Frameworks



A framework is a collection of parts-header files, libraries, images, sounds, and more-collected together to a single UN It.



A framework contains header files, libraries, pictures, sounds and even more into a single unit.



The header files for the Foundation framework take up nearly a megabyte of disk storage and contain more than 14,000 lines of code, spread across over a hundred files. When you include the master header file with #import <foundation/foundation.h>, and you get that whole vast collection.






Xcode is smart:it speeds up the task by using precompiled headers, a compressed and digested form of the header that ' s lo Aded quickly when you #import it.



Xcode is smart: It uses precompiled header files, compresses



1.4.3



NSLog and @ "Strings"



NSLog (@ "Hello, objective-c!");






The NS prefix:a prescription against Name collisions



NS prefix: Prevents name collisions.



Rather than break compatibility with code already written for NextSTEP, Apple just continued to use the "NS" prefix. It's a historical curiosity now, like your appendix.



Historical reason, originally neststep abbreviation NS. So it has been so abbreviated.



1.4.4



Nsstring:where it ' s @






A string in double quotes preceded by an at sign means, the quoted string should be treated as a Cocoa nsstring elemen T.



A double quote before the at sign @ means that the referenced string should be treated as a cocoa nssting element.



An nsstring are a sequence of characters in Cocoa.



A nsstring is some of the characters listed in cocoa.



NSString elements has a huge number of features packed into them and was used by Cocoa any time a string is needed. Here is just a few of the things an nsstring can do:



Tell your its length
Compare itself to another string
Convert itself to an integer or floating-point value






You can tell Xcode to always treat warnings as errors.



Setting up Xcode makes treating warnings like errors.















1.5 is you the Boolean type?



Many languages has a Boolean type, which is, the of course, a fancy term for variables that store true and false values. Objective-c is no exception.



OC also has a Boolean type.



The type is bool.









Objective-c Chapter 1-2 Hello World


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.