如何从包含路径的NSString创建FSRef?

sta*_*fan 3 filesystems macos cocoa objective-c

我在NSString中有一个文件系统路径,但我需要一个FSRef用于我将要进行的系统调用.创建FSRef的最佳方法是什么?

Jar*_*die 5

试试FSPathMakeRef:

NSString *path = @"Some... path... here";
FSRef f;
OSStatus os_status = FSPathMakeRef((const UInt8 *)[path fileSystemRepresentation], &f, NULL);

if (os_status == noErr) {
    NSLog(@"Success");
}
Run Code Online (Sandbox Code Playgroud)