简体   繁体   English

当我在ubuntu 16.04中使用self swift2时,无法将'String'类型的值转换为强制类型'NSString'

[英]cannot convert value of type 'String' to type 'NSString' in coercion when i use self swift2 with ubuntu 16.04

i have a problem with a code that throw the next message: 我有一个代码抛出下一条消息的问题:

error: cannot convert value of type 'String' to type 'NSString' in coercion
            return (self as NSString).substringWithRange(range)

I could resolve it before but not with a self calling, so here is the code: 我之前可以解决它而不是自我调用,所以这里是代码:

let range = expression.rangeOfFirstMatchInString(self, options: [], range: NSMakeRange(0, self.utf16.count))
    if range.location != NSNotFound {
        return (self as NSString).substringWithRange(range)
    }
    return nil

The swift compiler in Ubuntu won't auto recognize that NSString has a constructor that gets String as argument. Ubuntu中的swift编译器不会自动识别NSString有一个构造函数,它将String作为参数。 (at build time the compiler interprets it) (在构建时编译器解释它)

Instead do the work by your self by writing 而是通过写作来完成自己的工作

NSString(string: self)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在ubuntu 14.04的强制swift2中将“ NSString”类型的值转换为“ String”类型 - cannot convert value of type 'NSString' to type 'String' in coercion swift2 with ubuntu 14.04 无法强制将“[String]”类型的值转换为“NSString”类型 - Cannot convert value of type '[String]' to type 'NSString' in coercion 无法在强制转换中将[Struct]类型的值转换为[string]类型 - cannot convert value of type [Struct] to type [string] in coercion swift 无法在Swift中强制将类型'Void'转换为'String' - Cannot convert type 'Void' to 'String' in coercion in Swift Swift2:无法为类型'NSString'调用初始值设定项 - Swift2: Cannot invoke initializer for type 'NSString' Swift错误:无法将类型B的值转换为强制类型A. - Swift error: cannot convert value of type B to type A in coercion 无法转换'_?'类型的值 输入'[AFTParty]?' 在胁迫中 - 斯威夫特 - Cannot convert value of type '_?' to type '[AFTParty]?' in coercion - Swift 如何修复'无法将'[Any]'类型的值转换为强制类型'String'的错误 - How to fix 'Cannot convert value of type '[Any]' to type 'String' in coercion' error in swift 错误:无法将类型'ObjCBool​​'的值转换为Swift 4.1.2上的预期参数类型'Bool'以及Ubuntu 16.04上的Kitura - error: cannot convert value of type 'ObjCBool' to expected argument type 'Bool' on Swift 4.1.2 and Kitura on Ubuntu 16.04 在强制中无法将“Character”类型的值转换为“String”类型 - Cannot convert value of type 'Character' to type 'String' in coercion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM