Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C. Multiple anonymous categories?

About anonymous categories:

But can't I declare an anonymous category for the second time to split my variables' and methods' definitions?

I know that Xcode allows to do so, but will it work without problems?

UPDATED

I explain againg. The main question is can I use 2 categories without name (anonymous) in the same file or will they override/overlap each other? Is it clear now?

like image 282
user2083364 Avatar asked Dec 02 '22 20:12

user2083364


1 Answers

You can declare as many class extensions as you want. Each can contain instance variables and methods. As long as the compiler has seen all of the class extensions before it sees the @implementation of the class, it will work.

You should have one source file (with extension .m or .mm) that contains the @implementation of your class. That source file needs to contain all of the class extensions before the @implementation, so if you put your extensions in .h files, you need to include those .h files in that .m file.

UPDATE

To explicitly answer the question in your update: Yes. You can use two class extensions (anonymous categories) in the same file. Your class will contain the instance variables declared in both extensions, as long as the compiler sees both extensions in the same translation unit as the @implementation of the class.

like image 133
rob mayoff Avatar answered Dec 24 '22 10:12

rob mayoff