开发者

I am having trouble with compatibility between NSArray and NSMutableArray?

开发者 https://www.devze.com 2023-03-20 11:33 出处:网络
I am having trouble with compatibility between NSArray and NSMutableArray? --> Incompatible Objective-C types assigning \"struct NSArray *\", expected \"struct NSMutableArray\"

I am having trouble with compatibility between NSArray and NSMutableArray? --> Incompatible Objective-C types assigning "struct NSArray *", expected "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 开发者_C百科types assigning "struct NSArray *", expected "struct NSMutableArray"

I have tried making the "NSString declaration" to "NSMutableString"... made more problems.

thanks


You can't get a mutable array by doing

nsmarrRow = [nsstrFileContents componentsSeparatedByString: nsstrRowParse];

You will need to,

nsmarrRow = [NSMutableArray arrayWithArray:[nsstrFileContents componentsSeparatedByString: nsstrRowParse]];

Changing NSString to NSMutableString won't give you an NSMutableArray object. You will get an NSArray object just as in case of NSString. You will have to use that to get an NSMutableArray using the above method.


The componentsSeparatedByString method returns an NSArray. Try the following:

[NSMutableArray arrayWithArray:[nsstrFileContents componentsSeparatedByString: nsstrRowParse]];
0

精彩评论

暂无评论...
验证码 换一张
取 消