Multiple IBOutlets in same line of same type in Swift

无人久伴 提交于 2019-12-02 11:08:45

You have two options to get them in a single line.

The first is to use a Referencing Outlet Collection by defining this:

@IBOutlet var fields: Array<UITextField> = []

Then link your text fields to that. You can then access them as fields[0] and fields[1] respectively.

The other option is to define them in your file like this:

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!

Make your connections from Interface Builder, then edit the declarations to be in a single line like this:

@IBOutlet weak var emailField: UITextField!, passwordField: UITextField!

About you only options I'm afraid.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!