考慮下面的代碼正確的方式把NSString的內部NSMutableArray的方法
- (void) method1
{
list = [[NSMutableArray alloc] init];
NSString *f =[[NSString alloc] initWithCString: "f"];
[list addObject: f];
}
- (void) method2...
列表是一個類的實例變量中,我需要訪問所有的變量列表內的其他方法,例如方法2,當我分配一個NSString在方法1,我應該需要保留它嗎?我發現不需要保留?爲什麼?
'-initWithCString:'已棄用,因爲結果可能因用戶的默認字符編碼而異。要麼只是使用直接文字'NSString * f = @「f」;'或使用'-initWithCString:encoding:'或使用'-initWithUTF8String:' – JeremyP 2011-03-03 16:31:55