문제

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top