iosswiftswift2swift3.2

Cannot convert value of type String to specified type NSManagedObjectContext, While converting from Swift 2.3 -> 3.2


I need Help. While conversion from Swift 2.3 -> 3.2 I received below error. I'm not able to resolve this error.

Below is my coding stuff, where I'm facing some issues.

Error1 : Cannot convert value of type String to specified type NSManagedObjectContext**

Error2 : Cannot convert return expression of type URL to return type URL.

 class func persistentFileURL(_ name: String, enclosingDirectoryName: String) -> Foundation.URL {
        let directoryURL = self.directoryForPersistentStorage(enclosingDirectoryName)
        let urlPath = directoryURL.path
        let filePath: NSManagedObjectContext = (urlPath as NSString).appendingPathComponent(name) //Error1 : Cannot convert value of type String to specified type NSManagedObjectContext 
        
        return URL(context: filePath) // Error2 : Cannot convert return expression of type URL to return type URL.
    }

Note : URL is separate Class declared to handle this : URL_Class

Please help me. I'm very new to iOS. Not able to understand this type of error.


Solution

  • let filePath: NSManagedObjectContext = (urlPath as NSString).appendingPathComponent(name)

    should read

    let filePath: String = (urlPath as NSString).appendingPathComponent(name)