I am trying to save a bookmark into an xml file but am having difficulty
converting the bookmark to and from an NSString. Below is my code. I have
temporarily put it all in the NSDocument readFromURL method:
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
error:(NSError **)outError{
NSData *bookmark = [absoluteURL bookmarkDataWithOptions:
NSURLBookmarkCreationSuitableForBookmarkFile
includingResourceValuesForKeys:nil
relativeToURL:nil error:NULL];
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:
NSURLBookmarkResolutionWithoutUI relativeToURL:nil
bookmarkDataIsStale:NULL error:NULL];
[model newFile:[url path]];
// The above works. The following however doesn't:
NSString *str = [[NSString alloc] initWithData:bookmark
encoding:NSUTF16StringEncoding];
NSData *data = [str dataUsingEncoding:NSUTF16StringEncoding];
url = [NSURL URLByResolvingBookmarkData:data options:
NSURLBookmarkResolutionWithoutUI relativeToURL:nil
bookmarkDataIsStale:NULL error:NULL];
// url is nil here
[model newFile:[url path]];
return YES;
}
In the second part I am simply trying to convert the bookmark to and from a
string, but it fails. I have tried several encodings - NSUTF8StringEncoding,
NSUnicodeStringEncoding but no luck.
Can anyone point out what I might be doing wrong?
Thanks!
Peter_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]