Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 865
AP. Avatar asked Apr 17 '11 18:04

AP.


1 Answers

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.

like image 52
ughoavgfhw Avatar answered Oct 02 '22 20:10

ughoavgfhw