0
在swift 2中這個模糊的使用'下標' 有沒有人知道發生了什麼?模糊使用下標swift 2
var plistDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("myTip", ofType: "plist") {
plistDict = NSDictionary(contentsOfFile: path)
let plistArray = plistDict!["tip"]
let randV = Int(arc4random_uniform(UInt32(plistArray!.count)))
------->>>> let tipMessage = plistArray![randV] //error here???
let tipAlert = UIAlertController(title: "Something...", message: tipMessage as? String, preferredStyle: UIAlertControllerStyle.Alert)
tipAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
像這樣的東西?讓plistArray = plistDict![「tip」]爲! NSArray let randV = Int(arc4random_uniform(UInt32(plistArray!.count))) let tipMessage = plistArray [randV] –
是的,這看起來是正確的。儘管你應該儘量少用隱含解包的選項,因爲它不是很安全。 – Gavin
你會如何改變它?我總是樂於接受建議和學習... –