gpt4 book ai didi

ios - 下标swift 2的模糊使用

转载 作者:行者123 更新时间:2023-11-28 21:32:18 25 4
gpt4 key购买 nike

在 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))

最佳答案

当您从 plistDict 中获取 plistArray 时,它不知道它是什么类型的元素,所以它认为它是一个 AnyObject?。因此,它不知道如何处理您给它的下标,因为它不知道如何处理 AnyObject 类型的下标。如果在将 plistDict!["tip"] 分配给 plistArray 时将其转换为适当的类型,那么它应该能够弄清楚。

关于ios - 下标swift 2的模糊使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35419313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com