Question

I just got aware that there are some properties on objects of classes that have a dollar sign as prefix:

$height
$left
$origin
$size

... etc

I can use it as a setter e.g.

self.textField.$height = 44;

Q: how is this called, what is it good for and is it good practice to use is like this?

Was it helpful?

Solution

It seems that you are using category UIView+FrameAdditions.h.

More on categories here.

$ signs have no special meaning in this case - they are actually a bit unconventional to use in ObjC.

It is just a way developer named the helper methods in this category.

This $-prefix looks a bit strange but on the other hand it does help distinguish between native ObjC properties of UIView's frame and category helper methods.

Nick Farina (developer of this category) actually calls this as "kind of like jQuery for UIViews"

As for your question: is it a good practice to use it like this?

As said: $-sign is uncommon and i would ditch it personally. Especially if there is a chance that someone else will once work on the same project.

But the category itself can be very usefull and time-saving.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top