我試圖追加一個字符數組到NSString
。當我使用下面的代碼時,出現此錯誤:NSString stringWithUTF8String追加錯誤
********* initialization method -initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class NSCFString: Create a concrete instance!
這是什麼意思?怎麼修復?
NSString *str = [[NSString new] initWithString:@"Name: "];
NSString *name = [[NSString new] stringWithUTF8String:user.name];
//NSString *name = [[NSString stringWithUTF8String:seg.segname] copy]; //this also failed
str = [str stringByAppendingString:name];
另外,請不要在其他init選擇器中使用new。它基本上是一個alloc.init調用。 – Peteee24 2013-11-12 10:00:54