从Swift 2.3转换时,无法将String类型的值转换为指定的NSManagedObjectContext类型. 3.2 [英] Cannot convert value of type String to specified type NSManagedObjectContext, While converting from Swift 2.3 -> 3.2

查看:109
本文介绍了从Swift 2.3转换时,无法将String类型的值转换为指定的NSManagedObjectContext类型. 3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助.从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.

错误1:无法将字符串类型的值转换为指定的类型 NSManagedObjectContext **

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

错误2:无法将URL类型的返回表达式转换为返回类型URL.

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.
    }

注意:URL是声明为处理此问题的单独的类: URL_Class

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

请帮助我.我是iOS的新手.无法理解此类错误.

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

推荐答案

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

应阅读

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

这篇关于从Swift 2.3转换时,无法将String类型的值转换为指定的NSManagedObjectContext类型. 3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆