Swift, use string name to reference a variable

前端 未结 2 1584
自闭症患者
自闭症患者 2020-12-06 16:03

Plan to use a string value to for referencing which variable I want to update. Combining string from a few different user selected sources. To many possibilities to use if

2条回答
  •  余生分开走
    2020-12-06 16:18

    It is possible!!!

    let index = 1000
    if let d1000 = self.value(forKey: "d\(index)") as? Int {
        // enjoy
    }
    

提交回复
热议问题