2016-08-11 76 views
1

由於我最近更新到XCode 8 Beta 5,我一直試圖在我的appDelegate核心數據堆棧中解決這個錯誤。'FileManager'類型的值沒有成員'urlsForDirectory' - AppDelegate Swift 3錯誤

在這行代碼,我得到了以下錯誤:

// MARK: - Core Data stack 

lazy var applicationDocumentsDirectory: URL = { 
    // The directory the application uses to store the Core Data store file. This code uses a directory named "fitness.paceapp.Pace" in the application's documents Application Support directory. 
    let urls = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask) 
    return urls[urls.count-1] 
}() 

lazy var managedObjectModel: NSManagedObjectModel = { 
    // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. 
    let modelURL = Bundle.main.urlForResource("Dominos", withExtension: "momd")! 
    return NSManagedObjectModel(contentsOf: modelURL)! 
}() 

enter image description here

什麼可能會錯過我的任何想法。我很迷茫,在那裏沒有太多答案。提前致謝。

+1

你吃過看看新['FileManager' API參考(HTTPS: //developer.apple.com/reference/foundation/nsfilemanager)? – Hamish

+0

[FileManager和urlsForDirectory錯誤在Swift 3 Xcode Beta 4中可能的重複](http://stackoverflow.com/questions/38754426/filemanager-and-urlsfordirectory-error-in-swift-3-xcode-beta-4) –

回答

4

在這裏你去,

lazy var applicationDocumentsDirectory: URL = { 
     // The directory the application uses to store the Core Data store file. This code uses a directory named "fitness.paceapp.Pace" in the application's documents Application Support directory. 
     let urls = FileManager.default.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask) 
     return urls[urls.count-1] 
    }() 

    lazy var managedObjectModel: NSManagedObjectModel = { 
     // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. 
     let modelURL = Bundle.main.url(forResource: "Dominos", withExtension: "momd")! 
     return NSManagedObjectModel(contentsOf: modelURL)! 
    }() 
+0

非常感謝。 ;) – Gugulethu

0

是:

let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) 
return urls.last! 

或者

return try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) 
相關問題