gpt4 book ai didi

iphone - 将字典值写入 iOS 文件时出现无法识别的选择器错误

转载 作者:行者123 更新时间:2023-11-28 20:41:54 24 4
gpt4 key购买 nike

我正在读取一组 ALAsset 对象(在头文件中被指定为 NSMutableArray *assets;)。我正在尝试关注 this example为了将 ALAssets 字典的内容打印到文件中以便稍后检索。请注意,我可以正确地将字典键写入文件(注释掉),但不能写入值。

这是我在 viewDidLoad() 方法末尾运行的代码:

// Create path to Documents
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

if ([paths count] > 0) {
NSString *dictPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"dict.out"];
NSDictionary *aDict = [[assets objectAtIndex:0] valueForProperty:ALAssetPropertyURLs];

for (id key in aDict) {
NSLog(@"key: %@, value: %@", key, [aDict valueForKey:key]);
//[key writeToFile:dictPath atomically:YES]; <- THIS LINE WORKS
[[aDict valueForKey:key] writeToFile:dictPath atomically:YES];
}
}
else
NSLog(@"nope"); // The program doesn't get here.

日志看起来像这样:

2011-11-17 23:44:41.340 PhotoApp[542:12803] key: public.jpeg, value: assets-library://asset/asset.JPG?id=1000000001&ext=JPG

2011-11-17 23:44:41.361 PhotoApp[542:12803] -[NSURL writeToFile:atomically:]: unrecognized selector sent to instance 0x6455650

2011-11-17 23:44:41.370 PhotoApp[542:12803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL writeToFile:atomically:]: unrecognized selector sent to instance 0x6455650'


编辑:不确定是否重要,但该项目是针对 iPad 的,并且正在模拟器上运行。

最佳答案

问题是[[aDict valueForKey:key] writeToFile:dictPath atomically:YES]; 行。

key: public.jpeg, value: assets-library://asset/asset.JPG?id=1000000001&ext=JPG

你得到了 keypublic.jpegvalue

asassets-library://asset/asset.JPG?id=1000000001&ext=JPG

这是一个 NSURL 对象,所以当你使用时。

[[aDict valueForKey:key] writeToFile:dictPath atomically:YES];

代码然后 [aDict valueForKey:key] 返回不识别 writeToFile: 方法的 NSURL 对象。

关于iphone - 将字典值写入 iOS 文件时出现无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8177961/

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