我想将NSDictionary数组存储到一个文件中。所以我编写了一个从NSArray转换为NSString的函数。但是我遇到了一个非常奇怪的问题。这是我的代码。
+ (NSArray *)arrayForString:(NSString*)dataString
{
NSArray* stringArray = [dataString componentsSeparatedByString:ROW_SEPARATOR];
NSLog(@"%@", stringArray);
NSMutableArray* dictionaryArray = [[NSMutableArray alloc] initWithCapacity:0];
for (int i = 0; i < [stringArray count]; i++)
{
NSString* string = [stringArray objectAtIndex:i];
NSLog(@"%@", string);
NSArray* subStrings = [string componentsSeparatedByString:COLUMN_SEPARATOR];
NSDictionary* dic = [[NSDictionary alloc] initWithObjectsAndKeys:[subStrings objectAtIndex:0], PHOTO_NAME, [NSNumber numberWithUnsignedInt:[[subStrings objectAtIndex:1] unsignedIntValue]], PHOTO_SEQ_NO, nil];
[dictionaryArray addObject:dic];
}
return dictionaryArray;
}
这是日志:
2012-05-05 23:57:35.113 SoundRecognizer[147:707] (
"new Photo/0",
"new Photo/1"
)
2012-05-05 23:57:35.118 SoundRecognizer[147:707] new Photo/0
2012-05-05 23:57:35.123 SoundRecognizer[147:707] -[__NSCFString unsignedIntValue]: unrecognized selector sent to instance 0x1d18c0
如何从以下数组中获取@“ - ”?
2012-05-05 23:57:35.113 SoundRecognizer[147:707] (
"new Photo/0",
"new Photo/1"
)
答案 0 :(得分:2)
NSString没有unsignedIntValue
方法。请改用intValue
。但我不确定这一切 - 你可以使用writeToFile: atomically:
直接写一个字典数组(只要它们只包含属性列表类型)。