• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert NSString to FSRef
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert NSString to FSRef


  • Subject: Re: Convert NSString to FSRef
  • From: "Kevin Dixon" <email@hidden>
  • Date: Mon, 17 Mar 2008 11:44:00 -0400 (EDT)
  • Importance: Normal

Thanks for all the feed back, its been most helpful.

-Kevin

>
> On Mar 15, 2008, at 12:04 PM, Kevin Dixon wrote:
>
>> 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);
>
> -cString has been deprecated for a very long time; it's better to use
> UTF8String.  In this case, however, you can cast (NSString *) to
> CFStringRef.  Check the docs on toll-free bridging.
>
>> 	CFURLRef url = CFCreateURLWithString(NULL, cfFilePath, NULL);
>>
>> 	CFURLGetFSRef(url, &output);
>>
>> 	return output;
>> }
>>
>> I am getting a warning on the CFCreateURLWithString, saying
>> "initialization makes pointer from integer without a cast"
>
> There's no such function.  You probably meant CFURLCreate... instead.
> For an easier solution, try this:
>
> NSURL *aURL = [NSURL fileURLWithPath:filePath];
> CFURLGetFSRef((CFURLRef)aURL, &output);
>
> which also fixes your CFString and CFURL leaks.
>
> Another problem is that you have no way of returning an error in case
> CFURLGetFSRef fails, so you might want to either return the FSRef by
> reference and return a BOOL or pass in a BOOL * to return a failure
> value by reference.
>
> hth,
> Adam
>

_______________________________________________

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

References: 
 >Convert NSString to FSRef (From: "Kevin Dixon" <email@hidden>)
 >Re: Convert NSString to FSRef (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: Simple question
  • Next by Date: Re: NSButtonCell doesn't visually update during trackMouse:inRect:ofView:untilMouseUp:
  • Previous by thread: Re: Convert NSString to FSRef
  • Next by thread: Re: Convert NSString to FSRef
  • Index(es):
    • Date
    • Thread