·您现在的位置: 江北区云翼计算机软件开发服务部 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> Objective-cChapter1-2Helloworld

Objective-cChapter1-2Helloworld

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

 

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.在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 will be included only once, no matter how many times the #import directive is actually seen for that file.

#import 保证头文件只能被包含一次,不论#import 引入多少次这个文件。

 

1.4.2 

Introducing Frameworks

A framework is a collection of parts—header files, libraries, images, sounds, and more—collected together 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>, 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 loaded quickly when you #import it.

Xcode 很聪明: 它使用预编译头文件,压缩

1.4.3 

NSLog and @"Strings " 

NSLog (@"Hello, Objective-C!");

 

The NS Prefix: A Prescription Against Name Collisions

NS前缀: 预防名字冲突。

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.

历史原因,原来NestStep的缩写NS。所以一直这么简写了。

1.4.4

NSString: Where it's @

 

A string in double quotes preceded by an at sign means that the quoted string should be treated as a Cocoa NSString element.

一个在双引号前加at 符号@ 意思是说被引用的字符串应该视为cocoa NSSting 元素。

an NSString is a sequence of characters in Cocoa.

一个NSstring是一些列在cocoa中得字符。

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

   Tell you 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 . 

设置xcode使得对待警告如同错误。

 

 

 

1.5 Are you the  boolean type ?

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

oc 也有Boolean 类型。

类型是Bool 。