Xcode4 5出現時的OC新語法

2021-09-08 20:47:20 字數 4169 閱讀 4675

**

@synthesize 可以不用再寫了

如果在.**件裡有?

1@properynsobject* aproperty

那麼可以認為 編譯器會類似在.m檔案裡生成?

1@synthesizeaproperty = _aproperty

如果上面的都不認識 就可以認為 以下**?

12

3

4

5

6

7

8

9

@inte***cespouce:nsobject

@property(strong)nsobject* child

@end

@implementspouce

@end

和下面的**沒有太大區別(如果在arc時**retain、release。。。。)?

12

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

@inte***cespouce:nsobject

- (nsobject*) child;

- (void) setchild:(nsobject*) achild;

@end

@implementspouce

- (nsobject*) child

- (void) setchild:(nsobject*) achild

@end

@literals

@除了可以表示nsstring物件外。現在還可以表示數字、陣列、字典、和表示式?

12

3

4

5

6

7

8

nsstring* string = @"a string object";

nsnumber* numberfromnumber=@12;

nsnumber* numberfromexpression= @(20 + 40);

nsarray* array = @[obj1, obj2];

//注意上面不再需要nil結尾

nsdictionary* dictionary  = @;

//上面也不再需要了,而且key在value前面了。。

然後就是這些東西可以互相巢狀,比如?

1nsarray* array = @[@, @];

nsarray 和 nsdictionary 可以使用語法了

現在可以直接寫:?

12

idfirstelement = anarray[0];

anarray[0] = newvalue;

替代以前的?

12

idfirstelement = [anarray objectatindex:0];

[anarray replaceobjectatindex:0 withobject:newvalue];用?1

2

idvalue = adictionary[@"key"];

adictionary[@"key"] = newvalue;

替代以前的?

12

idvalue = [adictionary objectforkey:@"key"];

[adictionary setobject:newvalue forkey:@"key"];

在.m自己用的「私有」訊息可以不用clas***tension表達了。

想在.m檔案裡新增自己的一些訊息(方法、函式 同義)而不在.**件裡出現,可以在最近的clas***tension語法裡表達如下?

12

3

4

5

6

7

8

9

10

11

12

@inte***ceaclass ()

- (void) privatemethod;

@end

@implementaclass

- (void) privatemethod

@end

現在 可以直接在.m檔案裡寫,而編譯器不會出現警告此方法未宣告?

12

3

4

5

6

@implementaclass

- (void) privatemethod

@end

如果不知道clas***tension語法的,

我只想說,clas***tension是類似category語法的東西,在.m檔案內新增乙個無名的category的@inte***ce宣告,然後就可以在裡面寫私有方法宣告,避免編譯器亂提示警告。

如果不知道category語法。。。。。。。。。。。。。。。。

Xcode 4 5 中的新語法

xcode 4.5 開始,增加了如下新語法,可以讓我們提高 編寫效率,減少擊鍵次數。不過,這需要ios 4.3 的支援。1 陣列 從 xcode 4.5 開始,你可以這樣使用下標來訪問陣列 id object array 5 等於 id object array objectatindex 5 下標...

Xcode4 5中本地化問題

忽然發現在xcode4。5裡不會新增本地化字串了,localication的加號點開必須選擇資源檔案 首次新增是空的,無功而返 隨後搜尋到好文 而告知 名稱本地化參考 1 選中工程,在info中的localizations按 號,為infoplist.strings和storyboard建立本地化。...

UITableViewCell剛出現時,出現的動畫

void tableview uitableview tableview willdisplaycell uitableviewcell cell forrowatindexpath nsindexpath indexpathelse cell.alpha 0.0 uiview animatewit...