How to create IBOutlet collection pragmatically (swift4)

I am trying to add up the total of all of the textfields using an outlet collection the problem is put in all of the textfields programmatically so I cannot drag and drop it into the collection. How can I do this programmatically? You can see what I was trying to do but it is causing a compiling error.

             var a28 = UITextField()
    var a29 = UITextField()
     @objc func hitA31(_ textField: UITextField) {

   var fullTotal = 0
for view in a28,a29 {
    if let text = view.text, let num = Int(text) {
        fullTotal += num

    }
}
a31.text = String(fullTotal)
    }

hi @timswift,
your textfields need to be @IBOutlet prefixed to connect to IB. Secondly if you want to create a textfield from code, then you need to also add it to the subviews collection.

cheers,

Jayant

This topic was automatically closed after 166 days. New replies are no longer allowed.