Re: Convert NSString to FSRef
Re: Convert NSString to FSRef
- Subject: Re: Convert NSString to FSRef
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sat, 15 Mar 2008 20:25:19 +0100
Le 15 mars 08 à 20:04, Kevin Dixon a écrit :
I'm trying to write a method that will convert a NSString containing a
file system URL to an FSRef with the following code
- (FSRef)stringToFSRef: (NSString*)filePath {
FSRef output;
CFStringRef cfFilePath = CFStringCreateWithCString(NULL, [filePath
cString], (CFStringEncoding)8);
CFURLRef url = CFCreateURLWithString(NULL, cfFilePath, NULL);
CFURLGetFSRef(url, &output);
return output;
}
CFStringRef and NSString are tool-free bridged
you can do this:
CFURLRef url = CFCreateURLWithString(kCFAllocatorDefault,
(CFStringRef)filePath, NULL);
And you must release it when done (even with GC)
CFRelease(url);
and NSURL and CFURL are tool free bridged, so can do this:
CFURLGetFSRef((CFURLRef)[NSURL URLWithString:filePath], &output);
_______________________________________________
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