Ios 无法将类型字符串的值转换为指定的类型NSManagedObjectContext Swift 4
我需要帮助。从Swift 2.3->3.2转换时,我收到以下错误。我无法解决此错误 错误:无法将类型字符串的值转换为指定的类型NSManagedObjectContext 下面是我的代码,我面临一些问题Ios 无法将类型字符串的值转换为指定的类型NSManagedObjectContext Swift 4,ios,swift,swift2.3,swift3.2,Ios,Swift,Swift2.3,Swift3.2,我需要帮助。从Swift 2.3->3.2转换时,我收到以下错误。我无法解决此错误 错误:无法将类型字符串的值转换为指定的类型NSManagedObjectContext 下面是我的代码,我面临一些问题 class FileManager { class func directoryForPersistentStorage(_ directoryName: String) -> Foundation.URL { var urlToReturn: Foundation
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
}
}
错误1:无法将字符串类型的值转换为指定的NSManagedObjectContext类型**
注意:URL是单独声明的类,用于处理此:&
请帮帮我。我对iOS很陌生。无法理解这类错误。在哪一行出现错误?标有此注释的行=>//上面提到的#错误在这里只有两个相同的错误。在两条线上你检查这个是的我检查了那个。。。我们已经解决了这个错误。但这似乎更成问题。