我正在尝试从我的Firestore中检索总和的数字类型/值,到目前为止我的代码已经工作了,只是在price.text = "$\(product.price)
处显示"$可选值:30",而不是应该显示"$ 30"。
我已经使用了INT、FLOAT和DOUBLE(无论是? /!),但在标签中仍然得到相同的结果,显示"$Optional value: 30"。
当使用模拟器时,我只想消除价格标签中的“optional value”。
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)"
}
}
NumberFormatter
。 - vadian