Objective c 从NSString填充NSMutableArray

Objective c 从NSString填充NSMutableArray,objective-c,xcode,Objective C,Xcode,如果我有这个字符串: NSString *fileContent = [[NSString alloc] initWithContentsOfFile:groupPath]; …其中包含此内容(从路径): a、 b,c,d …如何使用上述对象填充阵列 我试过: self.itemArray = [[NSMutableArray alloc]init]; [itemArray initWithObjects:fileContent, nil]; ……目标是: [itemArray init

如果我有这个字符串:

NSString *fileContent = [[NSString alloc] initWithContentsOfFile:groupPath];
…其中包含此内容(从路径):

a、 b,c,d

…如何使用上述对象填充阵列

我试过:

 self.itemArray = [[NSMutableArray alloc]init];

[itemArray initWithObjects:fileContent, nil];
……目标是:

[itemArray initWithObjects:a, b, c, d, nil];

将字符串拆分为“,”并创建该数组的可变副本

如果字符串用
,“
分隔,则
NSString
中的方法就是您想要的。所以你会有这样的想法:

NSMutableArray* array = [[NSMutableArray alloc] initWithArray:[fileContent componentsSeparatedByString:@", "]];
self.itemArray = array;
[array release];

请你解释清楚一点好吗?在groupPath中,有一个文件在其中写入了“a、b、c、d”,因此如何将它们分开?您可以将文件的内容读入字符串。您可以通过[fileContent Components被字符串分隔:@“,”]来拆分该字符串,谢谢,我不知道有这个函数,我不明白,为什么是-2?这不是个好问题?