mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-26 21:40:44 +00:00
91 lines
2.1 KiB
Objective-C
91 lines
2.1 KiB
Objective-C
#import <CoreData/NSEntityDescription.h>
|
|
#import <CoreData/NSManagedObjectID.h>
|
|
#import <CoreData/NSManagedObjectModel.h>
|
|
#import <CoreFoundation/CFUUID.h>
|
|
#import <Foundation/NSRaise.h>
|
|
#import <Foundation/NSString.h>
|
|
#import <Foundation/NSURL.h>
|
|
|
|
@implementation NSManagedObjectID
|
|
|
|
- initWithEntity: (NSEntityDescription *) entity {
|
|
_entity = [entity retain];
|
|
_isTemporaryID = YES;
|
|
_storeIdentifier = nil;
|
|
|
|
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
|
_referenceObject = (NSString *) CFUUIDCreateString(NULL, uuid);
|
|
CFRelease(uuid);
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void) dealloc {
|
|
[_entity release];
|
|
[_storeIdentifier release];
|
|
[_referenceObject release];
|
|
[super dealloc];
|
|
}
|
|
|
|
/* NSManagedObjectID is hashed/equal by ptr value, they are uniqued per
|
|
persistent store and should be the same instance for all references to the
|
|
same underlying NSManagedObject
|
|
*/
|
|
|
|
- copyWithZone: (NSZone *) zone {
|
|
return [self retain];
|
|
}
|
|
|
|
- (NSEntityDescription *) entity {
|
|
return _entity;
|
|
}
|
|
|
|
- (NSString *) storeIdentifier {
|
|
return _storeIdentifier;
|
|
}
|
|
|
|
- (BOOL) isTemporaryID {
|
|
return _isTemporaryID;
|
|
}
|
|
|
|
- referenceObject {
|
|
return _referenceObject;
|
|
}
|
|
|
|
- (NSURL *) URIRepresentation {
|
|
NSString *path =
|
|
[[_entity name] stringByAppendingPathComponent: _referenceObject];
|
|
NSString *host = _isTemporaryID ? @"" : _storeIdentifier;
|
|
|
|
return [[[NSURL alloc] initWithScheme: @"x-coredata" host: host
|
|
path: path] autorelease];
|
|
}
|
|
|
|
- (NSPersistentStore *) persistentStore {
|
|
return _persistentStore;
|
|
}
|
|
|
|
- (void) setStoreIdentifier: (NSString *) value {
|
|
value = [value copy];
|
|
[_storeIdentifier release];
|
|
_storeIdentifier = value;
|
|
}
|
|
|
|
- (void) setReferenceObject: value {
|
|
_isTemporaryID = NO;
|
|
value = [value copy];
|
|
[_referenceObject release];
|
|
_referenceObject = value;
|
|
}
|
|
|
|
- (void) setPersistentStore: (NSPersistentStore *) store {
|
|
_persistentStore = store;
|
|
}
|
|
|
|
- (NSString *) description {
|
|
return [NSString stringWithFormat: @"<%@ %p temp=%d, ref=%@>", [self class],
|
|
self, _isTemporaryID, _referenceObject];
|
|
}
|
|
|
|
@end
|