我想将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"
)

最佳答案

NSString没有unsignedIntValue方法。请改用intValue。但是我不确定所有这一切的意义-您可以使用writeToFile: atomically:将字典数组直接写入文件(只要它们仅包含属性列表类型)。

关于ios - 我从NSString的'componentsSeparatedByString'方法获得了奇怪的输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10463611/

10-13 04:28
查看更多