簡體   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