为什么我收到有关 NSMutableArray 不兼容指针类型的警告?

发布于 2024-12-13 06:34:58 字数 901 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2024-12-20 06:34:58

componentsSeparatedByString: 返回一个 NSArray,而不是 NSMutableArray。如果您想要可变变体,请将最后一行更改为:

homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] mutableCopy];

componentsSeparatedByString: returns an NSArray, not an NSMutableArray. If you want the mutable variant, change the last line to:

homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] mutableCopy];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文