Objective-C學習 筆記

數據類型:

NS是Cocoa類對象類型的前綴,定義爲 NSxxxx * 實例名

@"字符串"; //@代表這個是NSString字符串,難道OC就沒有普通字符串了嗎?

NSString類型:

NSString *a = @"字符串!";  //這種定義,系統自動釋放

NSString *a = [[NSString alloc] initWithFormat:@"字符串!"];//這種定義需要手動釋放 [a release]

NSInteger和NSUInteger類型:

CGFloat類型:

 id, NSObject,init,float,double,char

 

(NSObject *)參數

修飾符 + 和 -,+爲普通方法,-爲靜態方法

 

實例化

foo= [類 new]

 

方法

[類|靜態類 方法 : 方法]

 

[Foo new] == [[Foo alloc] init] ??

 

資源管理

NSAutoreleasePool * pool = [NSAutoreleasePool new];//建立內存空間
context........
[pool drain];//釋放內存

@autoreleasepool{
      context........
}


 

發佈了13 篇原創文章 · 獲贊 3 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章