2016-06-27 95 views

回答

1

最一成不變的類可可有mutableCopy()方法返回的可變克隆本身。 NSString.mutableCopy()返回NSMutableStringNSData.mutableCopy()返回NSMutableData

然後,您可以從可可(NS*)橋接至基金會(CF*)類:

let str = "Hello world" 
let cfString = (str as NSString).mutableCopy() as! CFMutableString 
0

使用測試串let str: String = "test 123"

對於CFMutableString做:

(str as! CFMutableString) 

對於CFString你可以這樣做:

let cfStr: CFString = str 

(str as CFString) 

因爲演員總是成功。

1

CFMutableString是免費電話從NSMutableString橋接,你可以從你的字符串創建NSMutableString然後將其轉換爲CFMutableString

let str: String = "test 123" 
let cfmStr = NSMutableString(string: str) as CFMutableString