gpt4 book ai didi

ios - 我从 NSString 的 'componentsSeparatedByString' 方法得到了奇怪的输出

转载 作者:行者123 更新时间:2023-11-28 22:57:53 29 4
gpt4 key购买 nike

我想将 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com