我試圖刪除用戶錄製的視頻,現在已決定刪除該視頻。我有一個文件的URL,然後顯然也是一個路徑。在Swift中使用NSFileManager刪除文件時無法獲得完成結果
我已經嘗試使用文件和路徑的NSFileManager
類的刪除方法,但我無法獲得完成結果以確認文件是否實際上已被刪除。
下面是如何我試圖刪除文件在斯威夫特的例子:
let deleted = try! NSFileManager.defaultManager().removeItemAtURL(self.fileURL)
這會給我的Constant 'deleted' inferred to have type '()', which may be unexpected
使用removeItemAtPath
產生同樣的警告的警告。如果我運行的代碼,deleted
只需登錄爲()
如果我看的這兩種方法很明顯,他們不返回結果的方法簽名,而是採取例如爲removeItemAtURL
方法的文檔:true if the item was removed successfully or if URL was nil. Returns false if an error occurred. If the delegate aborts the operation for a file, this method returns true. However, if the delegate aborts the operation for a directory, this method returns false.
它也提到了參數error
,但沒有。然後最後在最後一句話中說:Returns YES if the item was removed successfully or if URL was nil.
作爲最後的手段我想我可以成爲NSFileManager
的代表,但它是委託協議不提供任何完成方法。
如何正確刪除文件或路徑,然後驗證它是否已被刪除?
「他們有很多工作要做更新文檔」 - 是的:) – user3344977