From 2ece3cabf209c2dbed4cb56fd21e40d7febd4338 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 20 Feb 2014 10:15:27 +0100 Subject: [PATCH] Add an uuid property to MP42Image. --- MP42/MP42Image.h | 3 ++- MP42/MP42Image.m | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/MP42/MP42Image.h b/MP42/MP42Image.h index 20e61bd..875ba94 100644 --- a/MP42/MP42Image.h +++ b/MP42/MP42Image.h @@ -23,11 +23,12 @@ typedef enum MP42TagArtworkType_e { NSURL *_url; NSData *_data; + NSString *_uuid; NSInteger _type; } -- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type; +- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type; - (instancetype)initWithImage:(NSImage *)image; - (instancetype)initWithData:(NSData *)data type:(NSInteger)type; - (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(NSInteger)type; diff --git a/MP42/MP42Image.m b/MP42/MP42Image.m index 2a6f4fe..d30b63e 100644 --- a/MP42/MP42Image.m +++ b/MP42/MP42Image.m @@ -9,11 +9,18 @@ #import "MP42Image.h" #import +@interface MP42Image () + +@property (atomic, readonly) NSString *uuid; + +@end + @implementation MP42Image @synthesize url = _url; @synthesize data = _data; @synthesize type = _type; +@synthesize uuid = _uuid; - (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type { @@ -82,9 +89,9 @@ - (NSData *)data { @synchronized(self) { - if (_data) + if (_data) { return _data; - else if (_url) { + } else if (_url) { NSError *outError = nil; _data = [[NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError] retain]; } @@ -111,9 +118,21 @@ return IKImageBrowserNSImageRepresentationType; } +- (NSString *)uuid +{ + @synchronized(self) { + if (_uuid == nil) { + _uuid = [[NSProcessInfo processInfo] globallyUniqueString]; + } + } + + return _uuid; +} + + - (NSString *)imageUID { - return [self.image description]; + return self.uuid; } - (id)imageRepresentation @@ -147,6 +166,7 @@ { [_image release]; [_data release]; + [_uuid release]; [super dealloc]; }