I need Help. While conversion from Swift 2.3 -> 3.2 I received below error. I'm not able to resolve this error.
Error : Cannot convert value of type String to specified type NSManagedObjectContext
Below is my coding stuff, where I'm facing some issues.
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 : Cannot convert value of type String to specified type NSManagedObjectContext**
Note : URL is separate Class declared to handle this : URL_Class & extension of URL Class
Please help me. I'm very new to iOS. Not able to understand this type of error.