为什么我收到有关 NSMutableArray 不兼容指针类型的警告?
我在 iPad 上收到一个简单的文本字符串,我试图简单地将其解析为表视图,但我收到以下警告:
"Incompatible pointer type assigning to 'NSMutableArray*' from 'NSArray'"
因此,controller.h
NSMutableArray *homeData;
@property (nonatomic, retain) NSMutableArray *homeData;
然后,controller.m
@synthesize homeData;
后跟
[searchData appendData:data];
NSString *searchString = [[NSString alloc] initWithData:searchData encoding:NSUTF8StringEncoding];
NSArray *sectionString = [searchString componentsSeparatedByString:@";;"];
homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] retain];
(data = 'no_home;;no_locl;;no_natl;;9:CHardaker;;')
在正常情况下,该字符串将包含一个索引号和缩写名称的列表,最多 100。
我在最后的 homeData 行收到警告。我期望 homeData objectAtIndex:0
应该是 no_home
,但事实并非如此,这是执行中唯一突出的问题。
I receive a simple text string on my iPad and I am trying to simply parse this into a table view, but I get the following warning:
"Incompatible pointer type assigning to 'NSMutableArray*' from 'NSArray'"
So, controller.h
NSMutableArray *homeData;
@property (nonatomic, retain) NSMutableArray *homeData;
then, controller.m
@synthesize homeData;
followed by
[searchData appendData:data];
NSString *searchString = [[NSString alloc] initWithData:searchData encoding:NSUTF8StringEncoding];
NSArray *sectionString = [searchString componentsSeparatedByString:@";;"];
homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] retain];
(data = 'no_home;;no_locl;;no_natl;;9:CHardaker;;')
Under normal circumstances, the string will hold a list of index numbers and abbreviated names, up to 100.
I get the warning on the final homeData line. I would expect that homeData objectAtIndex:0
should be no_home
, however it is not and this is the only issue outstanding in the execution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
componentsSeparatedByString:
返回一个NSArray
,而不是NSMutableArray
。如果您想要可变变体,请将最后一行更改为:componentsSeparatedByString:
returns anNSArray
, not anNSMutableArray
. If you want the mutable variant, change the last line to: