尝试将文件保存到磁盘时出现以下错误:
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;
}
我究竟做错了什么?