Kri*_*son 2 cocoa-touch objective-c
我在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"
Run Code Online (Sandbox Code Playgroud)
我已经尝试将"NSString声明"变为"NSMutableString"......制造了更多问题.
谢谢
你做不到一个可变数组
nsmarrRow = [nsstrFileContents componentsSeparatedByString: nsstrRowParse];
Run Code Online (Sandbox Code Playgroud)
你需要,
nsmarrRow = [NSMutableArray arrayWithArray:[nsstrFileContents componentsSeparatedByString: nsstrRowParse]];
Run Code Online (Sandbox Code Playgroud)
更改NSString到NSMutableString不会给你的NSMutableArray对象.你将得到一个NSArray对象,就像在案件中一样NSString.您必须使用它来获得NSMutableArray使用上述方法.