如何为类的可选属性分配值

问题描述 投票:0回答:1

我尝试了多种方法将值分配给stepperValue无效。我通过Firebase填写了进攻模型,我只是想为每个进攻“分配”一个步进值,以便进行计算,即点X stepperValue。

模型快速文件:

class Offence : Comparable {

var section: String
var name: String
var cost: Int
var points: Int
var stepperValue: Double?

init(section: String, name: String, cost: Int, points: Int) {
    self.section = section
    self.name = name
    self.cost = cost
    self.points = points
}

class Variables {

static var selectedOffencesArray: [Offence] = [Offence]()

}

此文件位于其自己的swift文件中的其自己的TableViewCell类中>

@IBAction func stepperValueChanged(_ sender: Any) {

 for offence in Variables.selectedOffencesArray {
        offence.stepperValue! = 3.0

    }

我尝试了多种方法将值分配给stepperValue无效。我通过Firebase填写了进攻模型,我只是想为每个进攻“分配”一个步进值,所以...

swift class properties optional stepper
1个回答
1
投票

以下仅能正常工作

© www.soinside.com 2019 - 2024. All rights reserved.