# How to create IBOutlet collection pragmatically (swift4)

**URL:** <https://forums.kodeco.com/t/how-to-create-iboutlet-collection-pragmatically-swift4/50155>\
**Category:** Swift\
**Created:** [September 20, 2018, 7:38pm UTC](https://forums.kodeco.com/t/how-to-create-iboutlet-collection-pragmatically-swift4/50155 "2018-09-20T19:38:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [September 20, 2018, 7:38pm UTC](https://forums.kodeco.com/t/how-to-create-iboutlet-collection-pragmatically-swift4/50155/1 "2018-09-20T19:38:34Z")

</div>

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)
    }

```

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [September 26, 2018, 9:42am UTC](https://forums.kodeco.com/t/how-to-create-iboutlet-collection-pragmatically-swift4/50155/2 "2018-09-26T09:42:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [March 6, 2019, 11:44am UTC](https://forums.kodeco.com/t/how-to-create-iboutlet-collection-pragmatically-swift4/50155/3 "2019-03-06T11:44:22Z")

</div>

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