Objective - c Chapter 1 -2 Hello world

來源:互聯網
上載者:User

標籤:

 

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 。

 

 

Objective - c Chapter 1 -2 Hello world

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.