iOS错误:从NSArray对象(类型'void')分配给NSMutableString?
问题描述:
我似乎无法解决这里出现的错误:“从不兼容类型'void'分配给'NSMutableString * __ strong'”。我试图追加的数组字符串值是一个NSArray常量。iOS错误:从NSArray对象(类型'void')分配给NSMutableString?
NSMutableString *reportString
reportString = [reportString appendString:[reportFieldNames objectAtIndex:index]];
答
appendString
是void
方法;你可能寻找
reportString = [NSMutableString string];
[reportString appendString:[reportFieldNames objectAtIndex:index]];
您可以通过它与初始化结合避免append
干脆:
reportString = [NSMutableString stringWithString:[reportFieldNames objectAtIndex:index]];
注意,存在需要的转让NSString
另追加方法:
NSString *str = @"Hello";
str = [str stringByAppendingString:@", world!"];
答
试试这个:
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方法。所以:
NSMutableString *reportString = [[NSMutableString alloc] init];
[reportString appendString:[reportFieldNames objectAtIndex:index]];
答
该方法的NSMutableString appendString:
不返回任何东西,所以你不能将它的不存在的返回值。这正是编译器试图告诉你的。你要么NSString和stringByAppendingString:
或者你想只使用[reportString appendString:[reportFieldNames objectAtIndex:index]];
而不分配返回值。
(当然,你需要创建一个字符串reportString
先走,但我假设你刚刚离开那出你的完整性问题。)
阅读文档,拜托.. 。 – 2012-11-08 21:22:50