我在NSArray和NSMutableArray之间的兼容性方面遇到了麻烦? - >不兼容的Objective-C类型分配“struct NSArray *”,期望“struct NSMutableArray”
NSMutableArray *nsmarrRow;
NSString *nsstrFilePath = [[NSBundle mainBundle] pathForResource: nsstrFilename ofType: nsstrExtension];
NSString *nsstrFileContents = [NSString stringWithContentsOfFile: nsstrFilePath encoding:NSUTF8StringEncoding error: NULL];
//break up file into rows
nsmarrRow = [nsstrFileContents componentsSeparatedByString: nsstrRowParse];//<--Incompatible Objective-C types assigning "struct NSArray *", expected "struct NSMutableArray"
我已经尝试将“NSString声明”设为“NSMutableString”......制造了更多问题。
感谢
答案 0 :(得分:5)
您无法通过
获取可变数组nsmarrRow = [nsstrFileContents componentsSeparatedByString: nsstrRowParse];
你需要,
nsmarrRow = [NSMutableArray arrayWithArray:[nsstrFileContents componentsSeparatedByString: nsstrRowParse]];
将NSString
更改为NSMutableString
不会为您提供NSMutableArray
个对象。您将获得NSArray
对象,就像NSString
一样。您必须使用它来使用上述方法获得NSMutableArray
。
答案 1 :(得分:2)
componentsSeparatedByString
方法返回NSArray。请尝试以下方法:
[NSMutableArray arrayWithArray:[nsstrFileContents componentsSeparatedByString: nsstrRowParse]];