I am having a very hard time getting copy/paste to work on my custom managed object Person
. The object contains properties and relationships. The object should provide the objectID. I intend to implement pasting generating a new object and then filling in the information from the copied Person
.
Copying the objectID probably does work. I am certain that pasting does not work. I have the following methods implemented in my Person
class, in an attempt to copy/paste an object:
#pragma mark --- Copy functionality
-(id)pasteboardPropertyListForType:(NSString *)type
{
if ( [type isEqualToString:@"my.company.person"])
{
NSManagedObjectID *oid = self.objectID;
NSURL *uidURL = [oid URIRepresentation];
return [uidURL absoluteString];
}
return nil;
}
-(NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard
{
return @[@"my.company.person"];
}
+ (NSPasteboardWritingOptions)writingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard
{
if ( [type isEqualToString:@"my.company.person"])
{
return NSPasteboardWritingPromised;
}
return nil;
}
and to do the pasting:
#pragma mark --- Paste functionality
+(NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard
{
return @[@"my.company.person"];
}
+ (NSPasteboardReadingOptions)readingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard
{
if ( [type isEqualToString:@"my.company.person"])
{
return NSPasteboardReadingAsString;
}
return nil;
}
- (id)initWithPasteboardPropertyList:(id)propertyList ofType:(NSString *)type
{
if ( [type isEqualToString:@"my.company.person"])
{
...
}
return nil;
}
How should I proceed here? I am at a loss, reading many stackoverflow Q&A's (e.g. Peter Hosey's great answer to NSPasteboard and simple custom data), as well as the Apple docs, still have me stumped on this one.