我有这段代码:
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil];
[pboard writeObjects:[NSArray arrayWithObject:[NSURL fileURLWithPath:@"/Users/dw/Desktop/macapp/Menulet/logo.png"]]];
我不想使用绝对路径,但当我尝试使用“logo.png”时,它会出现以下错误:
NSURLs written to the pasteboard via NSPasteboardWriting must be absolute URLs. NSURL 'logo.png -- file://localhost/Users/dw/Library/Developer/Xcode/DerivedData/Menulet-bvwpfkjlcufhxubvaxubgnubtfgi/Build/Products/Debug/' is not an absolute URL.
无论如何都不需要硬编码吗? logo.png目前位于Xcode的Resources文件夹中。
修改 我怎样才能获得目录路径?