1.0 在Swift中的 String 並沒有提供什么方法,直接把它自身轉變成 Int 、Float 等,而在OC中我們就可以這樣 "123".integerValue 來獲取它對應的數值,因為OC和Swift的字符串類型是相通的,所以我們可以進行如下操作:
var str1 = "123" let a = (str1 as NSString).integerValue //獲取數值 let b = (str1 as NSString).length // 獲取字符串的長度
所以我們只需要轉化成 OC的字符串類型,就可以獲取它對應的方法。這種方式用在 獲取 UITextField的值非常有用 .