CoreData, SyncServices & NSURL ...
CoreData, SyncServices & NSURL ...
- Subject: CoreData, SyncServices & NSURL ...
- From: Mic Pringle <email@hidden>
- Date: Thu, 5 Mar 2009 22:15:02 +0000
Hi,
I'm having a small problem with CoreData and SyncServices using the
Bookmarks schema (com.apple.bookmarks.Bookmark) located in
/System/Library/SyncServices/Schemas.
One of the entities of that schema is url, which is of type url, which
apparently maps to NSURL according to the Apple reference.
However, you can't store NSURL natively via CoreData, so the
references suggest using a transformer. I one setup okay so that when
I read the bookmarks it's transformed and stored correctly (as
follows) ...
- (id)reverseTransformedValue:(id)value
{
if (value == nil)
return nil;
NSURL *url = [NSKeyedUnarchiver unarchiveObjectWithData:value];
if (url) {
return [NSString stringWithString:[url absoluteString]];
} else {
return nil;
}
}
The problem lies when I try to transform back the other way, and then
push the changes. If I use the opposite, which is ...
- (id)transformedValue:(id)value
{
if (value == nil)
return nil;
NSURL *url = [NSURL URLWithString:value];
if (url) {
return [NSKeyedArchiver archivedDataWithRootObject:url];
} else {
return nil;
}
}
I get the error 'ISyncInvalidRecordException ISyncSession record
validation failure: Value pushed for property url on
com.apple.bookmarks.Bookmark is not of expected class NSURL (url),
rather NSCFString.'
If I try just returning an NSURL object which is what it seems to
want, as in ...
- (id)transformedValue:(id)value
{
if (value == nil)
return nil;
NSURL *url = [NSURL URLWithString:value];
if (url) {
return url;
} else {
return nil;
}
}
I get the error ...
*** -[NSURL bytes]: unrecognized selector sent to instance 0x1ac080
ISyncManager: exception raised during sync alert callout. A session
will not be created: *** -[NSURL bytes]: unrecognized selector sent to
instance 0x1ac080
Can anyone help with how to transform a string into an NSURL that will
cooperate with both CoreData and SyncServices ?
Thanks in advance as I'm really tearing out my hair with this one.
-Mic
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden