Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C class names with a +

Does a class name, say UIImage+Something or UIImageView+Somethingelse, mean that it acts like a custom UIImage or UIImageView?

like image 701
daihovey Avatar asked Jul 14 '11 00:07

daihovey


People also ask

What does @() mean in Objective-C?

In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals. '@' is used a lot in the objective-C world.

What is a category Objective-C?

A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Check the apple doc for the Category in Objective-C.

What are methods in Objective-C?

Basically in Objective-C, we call the function as method. The Objective-C foundation framework provides numerous built-in methods that your program can call. For example, method appendString() to append string to another string.

What is @implementation in Objective-C?

As noted, the @implementation section contains the actual code for the methods you declared in the @interface section. You have to specify what type of data is to be stored in the objects of this class. That is, you have to describe the data that members of the class will contain.


1 Answers

I think you are looking at the file names of Categories, not Classes. The plus character + is not allowed in class names or any other identifier in Objective-C.

An Objective-C category is a way of adding methods (but not instance variables) to a class you don't necessarily have the source to. For example, if you frequently want to make upside-down copies of UIImages, you can use a category to add a upsideDownImage method onto the UIImage class.

It's common to save this code in a file named UIImage+UpsideDown.m (with an accompanying header file, UIImage+UpsideDown.h).

like image 178
benzado Avatar answered Sep 28 '22 04:09

benzado