我正在尝试创建一个有效的文件 URL,它指向一个我知道存在的文件。
NSURL* fileURL = [NSURL fileURLWithPath:[@"~/Users/zak/global.scss"
stringByExpandingTildeInPath] isDirectory:NO];
NSLog(@"Looks like you want me to open a %@ file!", fileURL.pathExtension);
NSError *err;
if (![fileURL checkResourceIsReachableAndReturnError:&err]) {
NSLog(@"%@", err);
}
else {
NSLog(@"success!!!");
};
这总是导致编译器不断告诉我
Error Domain=NSCocoaErrorDomain Code=260 "The file “global.scss” couldn’t be
opened because there is no such file." UserInfo=0x1021937a0 {NSURL=file://
localhost/~/Users/zak/global.scss,
NSFilePath=/~/Users/zak/global.scss,
NSUnderlyingError=0x10212f4b0 "The operation couldn’t be completed.
No such file or directory"}
为什么这不起作用?我是否需要使用某种常量作为基本 URL?