【发布时间】:2020-02-12 18:50:42
【问题描述】:
我正在尝试从我的 Firestore 中为我的 Total 检索一个数字类型/值,到目前为止,我的代码一直在工作,它只是显示“$ optional value: 30”来代替应该显示的 price.text = "$\(product.price) “30 美元”。
我使用了 INT、FLOAT 和 DOUBLE(是否是?/!),但在显示“$Optional value: 30”的标签中仍然得到相同的结果
我只是想在使用模拟器时去掉价格标签中的“可选值”
import Foundation
import UIKit
class List {
var id: String
var name: String
var price: Float!
init(id: String,
name: String,
price: Float!) {
self.id = id
self.name = name
self.price = price
}
convenience init(dictionary: [String : Any]) {
let id = dictionary["id"] as? String ?? ""
let name = dictionary["name"] as? String ?? ""
let price = dictionary["price"] as? Float
self.init(id: id,
name: name,
price: price)
}
}
import UIKit
import Firebase
class ListCell: UITableViewCell {
weak var list: List!
@IBOutlet weak var productName: UILabel!
@IBOutlet weak var price: UILabel!
func configure(withList list: List) {
productName.text = product.name
price.text = "$\(product.price)"
}
}
【问题讨论】:
标签: ios json swift uitableview google-cloud-firestore