Multiple IBOutlets in same line of same type in Swift

前端 未结 1 1373
一向
一向 2021-01-28 19:02

In objective c you can declare IBOutlets in below mentioned manner:

IBOutlet UIButton *btn1, *btn2, *btn3;

And you can able to bind these butto

相关标签:
1条回答
  • 2021-01-28 19:23

    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.

    0 讨论(0)
提交回复
热议问题