![](/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.