0

我需要帮助。从 Swift 2.3 -> 3.2 转换时,我收到以下错误。我无法解决此错误。

错误: 无法将 String 类型的值转换为指定类型 NSManagedObjectContext

以下是我的编码资料,我遇到了一些问题。

class FileManager {
    class func directoryForPersistentStorage(_ directoryName: String) -> Foundation.URL {
        var urlToReturn: Foundation.URL!

        let libraryDirectory = (NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true) as [String]).first
        if let cLibraryDirectory = libraryDirectory {
            let expectedDirectoryPath = (cLibraryDirectory as NSString).appendingPathComponent(directoryName)
            let fileManager = Foundation.FileManager.default
            var isDirectory = ObjCBool(false)
            if (!fileManager.fileExists(atPath: expectedDirectoryPath, isDirectory: &isDirectory) || !isDirectory.boolValue) {
                do {
                    try fileManager.createDirectory(atPath: expectedDirectoryPath, withIntermediateDirectories: true, attributes: nil)
                } catch _ {
                }
            }
            urlToReturn = URL(context: expectedDirectoryPath) // Above mentioned #Error is Here

            if fileManager.fileExists(atPath: expectedDirectoryPath) {
                do {

                    try urlToReturn.setTemporaryResourceValue(true as AnyObject?, forKey: URLResourceKey.isExcludedFromBackupKey)

                } catch _ {
                }
            }
        }
        return urlToReturn
    }

    class func persistentFileURL(_ name: String, enclosingDirectoryName: String) -> Foundation.URL {
        let directoryURL = self.directoryForPersistentStorage(enclosingDirectoryName)
        let urlPath = directoryURL.path
        let filePath: String = (urlPath as NSString).appendingPathComponent(name)

        return URL(context: filePath) // Above mentioned #Error is Here
    }
}

Error1:无法将 String 类型的值转换为指定类型 NSManagedObjectContext**

注意:URL 是单独的类声明来处理这个:URL_ClassURL 类的扩展

请帮我。我对 iOS 很陌生。无法理解此类错误。

4

0 回答 0