0
我已經從應用程序中複製了像這樣的文件,並且完全複製了與其他應用程序中顯示的代碼完全相同的代碼,但由於什麼原因試圖運行此特定代碼時它只會創建新的目錄。從主包複製到應用程序支持swift
但是它不會將我保存在主包中的支持文件中的二進制文件保存到新目錄中。我做了大量的谷歌搜索和搜索堆棧溢出,並決定我可能不得不在這裏發佈一些東西。
let path = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent("youtube-dl")
let destination = "~/Library/Application Support/Youtube DLX/"
let destinationPath = destination.stringByStandardizingPath
NSFileManager.defaultManager().createDirectoryAtPath(destinationPath, withIntermediateDirectories: true, attributes: nil, error: nil)
NSFileManager.defaultManager().copyItemAtPath(path!, toPath: destinationPath + "youtube-dl", error: nil)
請注意,我試圖複製的文件沒有擴展等等全名就是「YOUTUBE-DL」
請不要忽略錯誤的參數。這是有原因的。 – 2014-10-29 06:36:38