AP.
AP.

Reputation: 5323

how to convert a path in NSString to CFURLRef and to FSRef*

I need to use several functions requiring CFURLRef and FSRef* and for the moment I just have a path stored in an NSString. What is the (most efficient) way to perform this conversion?

Thanks in advance for your help,

Upvotes: 12

Views: 16585

Answers (1)

ughoavgfhw
ughoavgfhw

Reputation: 39905

A path can be easily converted to a CFURL by using NSURL, which it is toll-free bridged with. There is also a CFURL function which will give you a FSRef for it. This code will give you both, given an NSString named thePath.

CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:thePath];
FSRef fileRef;
CFURLGetFSRef(url, &fileRef);

If you already have a valid pointer to a FSRef, you can pass it to CFURLGetFSRef directly.

Upvotes: 34

Related Questions