【发布时间】:2018-05-09 16:59:09
【问题描述】:
我在UIViewController 里面有UITableView
var userHistory: [[String: Any]] = [[String: Any]]()
override func viewDidLoad() {
Alamofire.request("http://...").responseJSON { (response) in
if let responseValue = response.result.value as! [String: Any]? {
if let responseFoods = responseValue["orders"] as! [[String: Any]]? {
self.userHistory = responseFoods
self.collectionView?.reloadData()
}
}
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "basCell", for: indexPath) as! BasCollectionViewCell
let history = userHistory[indexPath.row]
cell.numberLbl?.text = String(history["id"] as! Int)
cell.statusLbl?.text = (history["status"] as? String) ?? ""
let cost = String(history["price"] as! Int)
cell.sumLbl?.text = String(cost.dropLast(2)
cell.dateLbl?.text = (history["date"] as? String) ?? ""
return cell
}
问题是当我在模拟器、iPad mini、iPad Pro、iPhone 7 上测试时 - 一切都很好,没有错误
但是当我在 iPhone 5 上启动时给我错误:
致命错误:无法将 NSNumber 桥接到 Int:文件 /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-902.0.48/src/swift/stdlib/public/SDK/Foundation/NSNumber .swift,第 367 行
还有
线程 1:致命错误:无法将 NSNumber 桥接到 Int
对面let cost = String(history["price"] as! Int)
我不明白这是什么类型的问题
【问题讨论】:
-
什么是
userHistory?使用自定义结构或类而不是字典,然后你会神奇地摆脱这个问题。 -
@vadian ,我更新代码问题