![](/img/trans.png)
[英]cannot convert value of type 'NSString' to type 'String' in coercion swift2 with ubuntu 14.04
[英]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.