Objective c iOS错误:从NSArray对象(type';void';)分配给NSMutableString?

Objective c iOS错误:从NSArray对象(type';void';)分配给NSMutableString?,objective-c,ios,string-concatenation,nsmutablestring,Objective C,Ios,String Concatenation,Nsmutablestring,我似乎无法解决这里出现的错误:“从不兼容的类型'void'分配给'NSMutableString*.\uu strong'”。我试图附加的数组字符串值是一个NSArray常量 NSMutableString *reportString reportString = [reportString appendString:[reportFieldNames objectAtIndex:index]]; 试试这个: NSMutableString *reportString = [[NSM

我似乎无法解决这里出现的错误:“从不兼容的类型'void'分配给'NSMutableString*.\uu strong'”。我试图附加的数组字符串值是一个NSArray常量

NSMutableString *reportString     
reportString = [reportString appendString:[reportFieldNames objectAtIndex:index]];
试试这个:

NSMutableString *reportString = [[NSMutableString alloc] init];
[reportString appendString:[reportFieldNames objectAtIndex:index]];

appendString已将一个字符串附加到要向其发送消息的字符串:

[reportString appendString:[reportFieldNames objectAtIndex:index]];
这应该足够了。请注意,如果在Xcode 4.5中开发,也可以执行以下操作:

[reportString appendString:reportFieldNames[index]];

appendString
是一种
void
方法;您可能正在寻找

reportString = [NSMutableString string];
[reportString appendString:[reportFieldNames objectAtIndex:index]];
通过将其与初始化结合使用,您可以完全避免追加:

reportString = [NSMutableString stringWithString:[reportFieldNames objectAtIndex:index]];
请注意,
NSString
的另一个追加方法需要赋值:

NSString *str = @"Hello";
str = [str stringByAppendingString:@", world!"];

appendString是一个void方法。因此:

NSMutableString *reportString = [[NSMutableString alloc] init];
[reportString appendString:[reportFieldNames objectAtIndex:index]];

NSMutableString方法
appendString:
不返回任何内容,因此无法分配其不存在的返回值。这就是编译器想要告诉你的。您可以使用NSString和
stringByAppendingString:
,也可以只使用
[reportString appendString:[reportFieldNames objectAtIndex:index]]而不指定返回值


(当然,您需要先创建一个字符串才能进入
reportString
,但为了完整起见,我假设您没有考虑这个问题。)

请阅读文档,或者您可以执行
NSMutableString*reportString=[reportFieldNames[index]mutableCopy]。提供的大多数信息都接受答案,这意味着对所有人都最有帮助。从技术上讲,这不是Xcode 4.5技巧,而是“使用LLVM 4.1编译器”技巧。:)@cmac lemme注意到这样的问题与Xcode无关。Xcode只是围绕着Clang/GCC和iOS SDK的一个漂亮的礼物包装器。只是一个IDE。它本身不是一个编译器或开发。你甚至不用打开Xcode就可以轻松编写iOS应用程序。