繁体   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

我有一个代码抛出下一条消息的问题:

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

我之前可以解决它而不是自我调用,所以这里是代码:

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

Ubuntu中的swift编译器不会自动识别NSString有一个构造函数,它将String作为参数。 (在构建时编译器解释它)

而是通过写作来完成自己的工作

NSString(string: self)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM