@@ -159,7 +159,7 @@ - (UIImage *)image
159159 }
160160 return nil ;
161161}
162- #else
162+ #elif TARGET_OS_OSX
163163- (NSImage *)image {
164164 if (content == nil && writtenURL != nil ) {
165165 content = [[NSImage alloc ] initWithContentsOfFile: writtenURL.path];
@@ -275,12 +275,22 @@ - (void)removeFileWrapper:(LSFileWrapper *)fileWrapper {
275275 userInfo: nil ];
276276 return ;
277277 }
278- LSFileWrapper *existing = [fileWrappers objectForKey: fileWrapper.filename];
278+ [self removeFileWrapperWithFilename: fileWrapper.filename];
279+ }
280+
281+ - (void )removeFileWrapperWithFilename : (NSString *)filename_ {
282+ if (!isDirectory) {
283+ @throw [NSException exceptionWithName: NSInternalInconsistencyException
284+ reason: @" LSFileWrapper file is not a directory."
285+ userInfo: nil ];
286+ return ;
287+ }
288+ LSFileWrapper *existing = [fileWrappers objectForKey: filename_];
279289 if (existing.writtenURL ) {
280290 existing.deleted = YES ;
281291 }
282292 else {
283- [fileWrappers removeObjectForKey: fileWrapper.filename ];
293+ [fileWrappers removeObjectForKey: filename_ ];
284294 }
285295 updated = YES ;
286296}
@@ -551,7 +561,7 @@ - (BOOL)writeImage:(UIImage *)image_ toURL:(NSURL *)url error:(NSError *__autore
551561 return [imageData writeToURL: url options: NSDataWritingAtomic error: outError];
552562}
553563
554- #else
564+ #elif TARGET_OS_OSX
555565- (BOOL )writeImage : (NSImage *)image_ toURL : (NSURL *)url error : (NSError *__autoreleasing *)outError
556566{
557567 NSData *imageData;
@@ -650,35 +660,38 @@ - (BOOL)writeUpdates:(NSArray *)updates filemanager:(NSFileManager *)fileManager
650660 success = success && [fileManager createDirectoryAtURL: fileURL withIntermediateDirectories: NO attributes: nil error: outError];
651661 }
652662 }
653- else if ([fileContent isKindOfClass: [ NSData class ]]) {
663+ else {
654664 // Create the directories if they're missing
655665 NSURL * directoryURL = [fileURL URLByDeletingLastPathComponent ];
656666 if ([directoryURL checkResourceIsReachableAndReturnError: nil ] == NO ) {
657667 [[NSFileManager defaultManager ] createDirectoryAtURL: directoryURL withIntermediateDirectories: YES attributes: @{NSFileExtensionHidden : @YES } error: outError];
658668 }
659- success = [(NSData *)fileContent writeToURL: fileURL options: NSDataWritingAtomic error: outError];
660- }
661- else if ([fileContent isKindOfClass: [NSString class ]]) {
662- success = [(NSString *)fileContent writeToURL: fileURL atomically: YES encoding: NSUTF8StringEncoding error: outError];
663- }
669+ if ([fileContent isKindOfClass: [NSData class ]]) {
670+
671+ success = [(NSData *)fileContent writeToURL: fileURL options: NSDataWritingAtomic error: outError];
672+ }
673+ else if ([fileContent isKindOfClass: [NSString class ]]) {
674+ success = [(NSString *)fileContent writeToURL: fileURL atomically: YES encoding: NSUTF8StringEncoding error: outError];
675+ }
664676#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
665- else if ([fileContent isKindOfClass: [UIImage class ]]) {
666- success = [self writeImage: (UIImage *)fileContent toURL: fileURL error: outError];
667- }
668- else if ([fileContent isKindOfClass: [ALAsset class ]]) {
669- success = [self writeAsset: (ALAsset *)fileContent toURL: fileURL fileManager: fileManager error: outError];
670- }
671- #else
672- else if ([fileContent isKindOfClass: [NSImage class ]]) {
673- success = [self writeImage: (NSImage *)fileContent toURL: fileURL error: outError];
674- }
677+ else if ([fileContent isKindOfClass: [UIImage class ]]) {
678+ success = [self writeImage: (UIImage *)fileContent toURL: fileURL error: outError];
679+ }
680+ else if ([fileContent isKindOfClass: [ALAsset class ]]) {
681+ success = [self writeAsset: (ALAsset *)fileContent toURL: fileURL fileManager: fileManager error: outError];
682+ }
683+ #elif TARGET_OS_OSX
684+ else if ([fileContent isKindOfClass: [NSImage class ]]) {
685+ success = [self writeImage: (NSImage *)fileContent toURL: fileURL error: outError];
686+ }
675687#endif
676- else {
677- NSData *data = [NSPropertyListSerialization dataWithPropertyList: fileContent
678- format: NSPropertyListBinaryFormat_v1_0
679- options: 0
680- error: NULL ];
681- success = data && [data writeToURL: fileURL atomically: YES ];
688+ else {
689+ NSData *data = [NSPropertyListSerialization dataWithPropertyList: fileContent
690+ format: NSPropertyListBinaryFormat_v1_0
691+ options: 0
692+ error: NULL ];
693+ success = data && [data writeToURL: fileURL atomically: YES ];
694+ }
682695 }
683696
684697 if (success == NO ) {
0 commit comments