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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With