Objective-C Naming UILabel iOS

I have been wondering for a long time what to do with this.

Suppose I will create a UILabel, this label will contain a name. Therefore, without hesitation, I will call this name UILabel | name |.

Then I will have an NSString that will contain the actual name string. Therefore, I think the string name | name | would be more correct?

But what would I call UILabel?

I thought about calling it labelName.

But is it a Hungarian notation that is very discouraged?

Is this a dead end?

+4
source share
3 answers

Objective-C is a verbose language. Usually, when they are called, they include the type of variables and parameters.

UILabel *nameLabel = ... NSString *name = ... 

In the case of primitive values ​​(or even NSStrings and NSNumbers), the type is usually omitted.

+8
source

Whenever you get such a situation, think, rethink and change the names.

In your case, you can use:

 UILabel *nameLabel; NSString *name; //*nameString; // *nameValue; 

You can suffix the type (although this is not good practice, but there are exceptions), as in the following example.

nameArray not a good name; it must be names

 NSArray *names; // instead of nameArray 
+6
source

I would say that your main problem is that your model is leaking into the view. Your label (obviously view) should preferably not know anything about the model it represents.

Take, for example, a look at the UITableViewCell . It has outputs called

  • textLabel
  • detailTextLabel
  • imageView

They can be used to represent almost any model data that has some body text and possibly an image and / or more text.

You may also notice that in these UIKit examples the suffixes of the variable are of type (adding a Label at the end of the label). The same applies to the backgroundColor property in the UIView.

0
source

All Articles