Alberto Schiariti
Alberto Schiariti

Reputation: 1579

Xcode - Custom Class with a subproject

I have a project A within another project B. In the Project A I have the "core" of my program and in the Project B I do the customize things. I created also some empty custom class in Project A, so that I can ovverride them in the Project B.

For example... In Project A I have the class Square.h with all methods and an empty SquareCustom.h which is a subclass of Square. Then I have a class Shapes.h which include SquareCustom.

In the Project B I import Square.h and Shapes.h, but I write a new SquareCustom.h with my custom methods. I do this because I can keep the same Shape.h that point to SquareCustom.h whetever the project is.

My problem now is that when I work on SquareCustom.xib on Project B Xcode get a bit messy. SquareCustom.xib file owners is the correct SquareCustom from Project B when I compile, but in the Interface Builder if I press the arrow near the "Custom class" in the Identity Inspector it points to the wrong one (the whole one from Project A). This is really annoying because I always have to choose it manually when I work with the assistant editor.

What I am doing wrong?

Upvotes: 1

Views: 109

Answers (1)

Olotiar
Olotiar

Reputation: 3274

So if I understand correctly you have 2 SquareCustom classes, one in project A and an other in project B ?

This is a class name collision, and should be avoided like hell. This is the reason why Apple recommends prefixing class names with uppercase letters. You should not be trying to create one on purpose.

This is your problem. What is the point of having SquareCustom in project A anyway, considering that it is empty ?

The logical way to do it for me would be to have Square in project A and then create CustomSquare in project B as a subclass of Square (from project A). This seems to be a clean design (project A which acts as an extern library does not know about its consumers, you don't duplicate class names), it achieves what I understand you wanna do. And IB would get less confused about which CustomSquare to use considering that there would be only one now.

Upvotes: 1

Related Questions