• 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: Why is NSString->FSRef so hard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is NSString->FSRef so hard?


  • Subject: Re: Why is NSString->FSRef so hard?
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 25 Apr 2009 20:05:42 -0500

On Apr 25, 2009, at 7:28 PM, Erg Consultant wrote:

I was using CFURLGetFSRef passing in the NSString which works fine as long as the path contains no special chars. If it does, CFURLGetFSRef returns nil.

File path strings aren't URLs. Even a string which looks a bit URL- ish (for example, if you just tack "file://" on the front of a path) isn't a URL. It's not a valid URL string; it is especially not a CFURL or NSURL object!


If you've got a path string and you want to make a URL referencing the same file, you have to do it the right way. As mentioned, +fileURLWithPath: is one good way. CFURLCreateWithFileSystemPath also works.

Wrong ways include +URLWithString: (and the other ...WithString... methods of NSURL) and CFURLCreateWithString. Those are only appropriate if your have a proper URL string (with characters that aren't legal in a URL escaped). Passing an NSString to a function which expects a CFURLRef is asking for trouble. Having it work or return nil is luck; it was just as like to crash your program.

Regards,
Ken

_______________________________________________

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: 
 >Why is NSString->FSRef so hard? (From: Erg Consultant <email@hidden>)
 >Re: Why is NSString->FSRef so hard? (From: Nick Zitzmann <email@hidden>)
 >Re: Why is NSString->FSRef so hard? (From: Erg Consultant <email@hidden>)

  • Prev by Date: Re: Why is NSString->FSRef so hard?
  • Next by Date: Re: Why is NSString->FSRef so hard?
  • Previous by thread: Re: Why is NSString->FSRef so hard?
  • Next by thread: Re: Why is NSString->FSRef so hard?
  • Index(es):
    • Date
    • Thread