ファイルをディスクに保存しようとすると、次のエラーが発生します。
ERROR IS Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x8d44150 {NSFilePath=/Users/test/Library/Application Support/iPhone Simulator/5.1/Applications/C283C4FF-645A-4C97-BB87-9591ECC57B0D/Library/Caches/newsfeedCache, NSUnderlyingError=0x8d25870 "The operation couldn’t be completed. Is a directory"}
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"test", @"hula", nil];
[archiver encodeObject:dict forKey:kDataKey];
[archiver finishEncoding];
NSLog(@"CACHE PATH IS %@", self.newsfeedCachePath_);
NSError *error = nil;
BOOL success = [data writeToFile:self.newsfeedCachePath_ options:NSDataWritingAtomic error:&error];
if (success && !error){
} else {
FNLog(@"ERROR IS %@", [error description]);
}
[archiver release];
[data release];
パスを作成する方法は次のとおりです。
- (NSString *)createDataPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:cacheName];
/* check for existence of cache directory */
if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
return dataPath;
}
NSError *error = nil;
/* create a new cache directory */
if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath
withIntermediateDirectories:NO
attributes:nil
error:&error]) {
DLog(@"Unresolved error %@, %@", error, [error userInfo]);
return nil;
}
NSString *path = [dataPath stringByAppendingPathComponent:cachePath];
return path;
}
私は何を間違っていますか?