0

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

1 回答 1

2

NSString 没有unsignedIntValue方法。改为使用intValue。但我不确定这一切的意义——无论如何,您都可以使用writeToFile: atomically:.

于 2012-05-05T18:00:03.537 回答