6

I did search around and I found a bunch of conventions but none talk about IBOutlets.

Which one of the following should I use?

@IBOutlet weak var price: UITextField!
@IBOutlet weak var priceTextField: UITextField!
@IBOutlet weak var textFieldPrice: UITextField!
@IBOutlet weak var tfPrice: UITextField!
Essam Fahmi
  • 1,920
  • 24
  • 31
Marcelo
  • 1,176
  • 1
  • 10
  • 29
  • 2nd and especially the 3rd sound and look very bad, if anything use the 1st or `priceTextField`, including the type *after* the actual meaning of the field. – luk2302 Jan 01 '16 at 16:08
  • True, forgot about that option. I just added it to the questions. – Marcelo Jan 01 '16 at 16:11
  • Also note that most modern naming conventions prefer not to include "type" in variable names. Personally, I would name the variable just `priceField`. If you then change the type to `UISearchField` or other class, you won't have to rename it. – Sulthan Jan 01 '16 at 16:13

1 Answers1

6

This is the naming convention for IBOutlets that I often see the most in the developer's code.

@IBOutlet weak var priceTextField: UITextField!
Kiet Nguyen
  • 609
  • 4
  • 8
  • 7
    What about when you have 5 UITextFields and you forgot how you named that 4th text field, wouldn't it be easy to name those text fields textFieldUsername, now if you forgot the name you can always start with textField and wait for auto completion from Xcode. – OhadM Jan 18 '16 at 13:13
  • 1
    @Oh If you forgot the name, or the name is difficult to come up if you know the exact usage, that mean, the naming of that text field maybe in a problem. The naming convention of an item should always clearly defined across team. – MatthewLuiHK Feb 26 '18 at 03:38