我有这段代码:
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 资源文件夹中。
编辑: 我怎样才能获得目录路径?