OBJECTIVE-C 基礎教學1/5 codeschool




OBJECTIVE-C 基礎教學1/5 codeschool
//最簡單印出文字的方式
NSLog(@"Hello, Mr. Higgie.");

//宣告String型別以及命名變數來儲存字串
NSString *firstName = @"Daris";

//將變數名稱印出來
NSLog(firstNeme);

//與字串結合%@的部分將會被變數firstName取代
NSLog(@"Hello there, %@.", firstName);

//可以重複印出字串變數
NSLog(@"%@ %@", firstName, firstName);

//再次練習第二行的變數命名與宣告
NSString *lastName = @"jobs";

//可以隨意的呼叫你所宣告的變數
NSLog(@"%@ %@", firstName, lastName);

//宣告數字,不需要加雙括號
NSNumber *age = @20;

//數字也可以被呼叫
NSLog(@"%@ is %@ years old", firstName, age);

//宣告陣列
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];

//結果:Lettertouch 因為印出陣列apps的第二個字串,值是Lettertouch
//呼叫方法是apps[1]
NSLog(@"%@",apps[1] );

//更改上方apps變數的值
apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot", @"Instacanvas"];

//關鍵字功能Dictionary
NSDictionary *appRatings = @{@"AngryFowl": @3, @"Lettertouch": @5};

//因為@5對照的字串是Lettertouch所以當曾經宣告過@"Lettertouch": @5
//只要呼叫出@5即可顯示字串
NSLog(@"Lettertouch has a rating of %@.", @5);


整理宣告方式:
NSLog(@"Hello, Mr. Higgie.")
NSLog(@"Hello there, %@.", firstName);
NSLog(@"%@ %@", firstName, firstName);
NSLog(@"%@",apps[1] );
NSLog(@"Lettertouch has a rating of %@.", @5);

NSString *lastName = @"jobs";
NSNumber *age = @20;
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
NSDictionary *appRatings = @{@"AngryFowl": @3, @"Lettertouch": @5};

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除