diff --git a/MP42/MP42Image.h b/MP42/MP42Image.h index 216cb28..de3ac85 100644 --- a/MP42/MP42Image.h +++ b/MP42/MP42Image.h @@ -18,7 +18,7 @@ typedef enum MP42TagArtworkType_e { MP42_ART_PNG = 4 } MP42TagArtworkType; -@interface MP42Image : NSObject +@interface MP42Image : NSObject - (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type; - (instancetype)initWithImage:(NSImage *)image; diff --git a/MP42/MP42Image.m b/MP42/MP42Image.m index c1d01cf..51574f4 100644 --- a/MP42/MP42Image.m +++ b/MP42/MP42Image.m @@ -34,7 +34,7 @@ - (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type { if (self = [super init]) { - _url = [url retain]; + _url = url; _type = type; } @@ -44,7 +44,7 @@ - (instancetype)initWithImage:(NSImage *)image { if (self = [super init]) - _image = [image retain]; + _image = [image copy]; return self; } @@ -52,7 +52,7 @@ - (instancetype)initWithData:(NSData *)data type:(NSInteger)type { if (self = [super init]) { - _data = [data retain]; + _data = [data copy]; _type = type; } @@ -93,7 +93,7 @@ [image addRepresentation:imageRep]; } - return [image autorelease]; + return image; } - (NSData *)data { @@ -102,7 +102,7 @@ return _data; } else if (_url) { NSError *outError = nil; - _data = [[NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError] retain]; + _data = [NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError]; } } @@ -115,7 +115,7 @@ if (_image) return _image; else if (self.data) { - _image = [[self imageFromData:_data] retain]; + _image = [self imageFromData:_data]; } } @@ -131,7 +131,7 @@ { @synchronized(self) { if (_uuid == nil) { - _uuid = [[[NSProcessInfo processInfo] globallyUniqueString] retain]; + _uuid = [[NSProcessInfo processInfo] globallyUniqueString]; } } @@ -148,12 +148,19 @@ return self.image; } ++ (BOOL)supportsSecureCoding +{ + return YES; +} + - (void)encodeWithCoder:(NSCoder *)coder { - if (_data) + if (_data) { [coder encodeObject:_data forKey:@"MP42Image_Data"]; - else + } + else { [coder encodeObject:_image forKey:@"MP42Image"]; + } [coder encodeInteger:_type forKey:@"MP42ImageType"]; } @@ -162,21 +169,12 @@ { self = [super init]; - _image = [[decoder decodeObjectForKey:@"MP42Image"] retain]; - _data = [[decoder decodeObjectForKey:@"MP42Image_Data"] retain]; + _image = [decoder decodeObjectOfClass:[NSImage class] forKey:@"MP42Image"]; + _data = [decoder decodeObjectOfClass:[NSData class] forKey:@"MP42Image_Data"]; _type = [decoder decodeIntForKey:@"MP42ImageType"]; return self; } -- (void)dealloc -{ - [_image release]; - [_data release]; - [_uuid release]; - - [super dealloc]; -} - @end diff --git a/MP42Foundation.xcodeproj/project.pbxproj b/MP42Foundation.xcodeproj/project.pbxproj index 4ac6da1..7f85520 100644 --- a/MP42Foundation.xcodeproj/project.pbxproj +++ b/MP42Foundation.xcodeproj/project.pbxproj @@ -160,7 +160,7 @@ A9B9C2811823923200416A4E /* MP42HtmlParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2361823923100416A4E /* MP42HtmlParser.h */; }; A9B9C2821823923200416A4E /* MP42HtmlParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2371823923100416A4E /* MP42HtmlParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; A9B9C2831823923200416A4E /* MP42Image.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2381823923100416A4E /* MP42Image.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A9B9C2841823923200416A4E /* MP42Image.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2391823923100416A4E /* MP42Image.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + A9B9C2841823923200416A4E /* MP42Image.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2391823923100416A4E /* MP42Image.m */; }; A9B9C2851823923200416A4E /* MP42MediaFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C23A1823923100416A4E /* MP42MediaFormat.h */; settings = {ATTRIBUTES = (Public, ); }; }; A9B9C2861823923200416A4E /* MP42MediaFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C23B1823923100416A4E /* MP42MediaFormat.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; A9B9C2871823923200416A4E /* MP42Metadata.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C23C1823923100416A4E /* MP42Metadata.h */; settings = {ATTRIBUTES = (Public, ); }; };