我有下一个将 NSSet 转换为用逗号分隔的字符串的代码:
-(NSString *)toStringSeparatingByComma
{
NSMutableString *resultString = [NSMutableString new];
NSEnumerator *enumerator = [self objectEnumerator];
NSString* value;
while ((value = [enumerator nextObject])) {
[resultString appendFormat:[NSString stringWithFormat:@" %@ ,",value]];//1
}
NSRange lastComma = [resultString rangeOfString:@"," options:NSBackwardsSearch];
if(lastComma.location != NSNotFound) {
resultString = [resultString stringByReplacingCharactersInRange:lastComma //2
withString: @""];
}
return resultString;
}
似乎它有效,但我在这里收到两个警告:
1. format string is not a string literal (potentially insecure)
2. incompatible pointer types assigning to nsmutablestring from nsstring
如何重写它以避免警告?