我不确定如何从声明的列表中选择特定值。我猜答案与我正在尝试的相差不远。我做错了什么?
private class HostCell: UICollectionViewCell {
private var hostController: UIHostingController<Cell>?
override func prepareForReuse() {
if let hostView = hostController?.view {
hostView.removeFromSuperview()
}
hostController = nil
}
var hostedCell: Cell? {
willSet {
guard let view = newValue else { return }
hostController = UIHostingController(rootView: view, ignoreSafeArea: true)
if let hostView = hostController?.view {
hostView.frame = contentView.bounds
hostView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
contentView.addSubview(hostView)
}
}
}
}
答案 0 :(得分:0)
如果您使用括号表示法来获取属性值,则必须提供带有属性名称的字符串。例如,在下面的代码摘录中,您指的是一个名为“prop_10”的变量,即 undefined
。
selected[prop][prop_10]
因此,正确的应该是:
selected[prop]['prop_10']