草庐IT

removeItemAtPath

全部标签

ios - 将代码从 Swift 1.2 转换为 Swift 2.0 以进行错误处理

swift1.2代码:varerror:NSError?=nilif(fileManager.removeItemAtPath(exportPathasString,error:&error)){//Error-handleifrequried}当我使用try和catchblock时,我无法将此代码编译为Swift2.0。Swift2.0代码do{check=tryfileManager.removeItemAtPath(exportPathasString)if(//somecondition){//whatever}}catch{check=nil} 最

iphone - NSFileManager removeItemAtPath 锁定主线程

我正在开发一款可以删除大量文件的应用程序。当我调用NSFileManager的removeItemAtPath方法时,应用程序的UI会锁定,直到操作完成(这可能需要一段时间)。我尝试通过调用使用performSelectorInBackground的方法来修复此问题,但它不起作用。有什么想法吗?提前致谢。 最佳答案 您可以尝试使用GCD在后台线程中执行此操作。dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^(void){[[NS