I am having a compilation problem so befuddling to me that I'm
suspecting the answer must be incredibly easy -- typical cross-eyed
developer syndrome that happens when coding for very long hours.
Anyway, here's the deal:
I have an iPhone application project A, which is dependent upon static
library B. In project B, I have two classes, X and Y, which are
totally unrelated to one another, and have no references to one
another at all. However, in each class, there is an init method with a
similar signature.
In X:
- (id) initiWithDelegate:(id <XDelegate>)delegate;
In Y:
- (id):initWithDelegate:(id <YDelegate>)delegate;
Switch back to project A, where I have a class Z, which imports class
X, and implements XDelegate, but has no references whatsoever to class
Y, no imports of Y, nothing, and doesn't implement YDelegate. Here is
the thing which has me beat right now -- in class Z there is a line of
code which creates an instance of X:
X *xobject = [[X alloc] initWithDelegate:self];
When I compile project A, I get a compile warning on this line of code
which says something to the effect that "A doesn't implement
YDelegate". Huh? Check this out, I can even completely remove the init
method declaration and implementation entirely from class X and it
won't change the error message. However, if I change the interface
declaration for X to this:
- (id) initiWithMyDelegate:(id <XDelegate>)delegate;
everything compiles cleanly. There is NO relationship between X and Y,
and there's nothing Z otherwise does that has anything to do with Y. I
have checked the code over and over and tested this thing for about 2
hours now, and I don't get it -- the answer must be something simple,
but the thought that there's something about iPhone static libraries
and/or headers that prevents me from using the same method signature
across two completely unrelated classes just can't be right.
Does anyone have any insight to the problem here?
Thanks,
Brad
Interesting....I've been using static libs for a while now, so its not
something I'm unfamiliar with, nor do I think its particularly complex
-- but it is a bit of a nuisance in project configuration. My general
thoughts on the article are as follows:
- I get the point about the problem with actual used code, but that
just an issue of library organization for the most part, but OK, I get
that. In my case, I have some isolated chunks of code all moving
toward the grand convergence in a new static lib.
- One of the problems I'm experiencing with IB would likely be
partially resolved with this. I've discovered that subclassing any UI
components such as UIView and UIViewController (which I am) in a
static library may be wreaking havoc in IB. You actually have to drag
your header files into IB, which isn't a pain in itself, but I'm
suspecting one of my problems may have to do with IB not staying in
sync with header changes on the file system.
- The other problem I'm experiencing with IB I'm not sure -- I've been
experiencing it for a couple of months now, on both old / new projects
and multiple machines -- was introduced when Snow Leopard and
compatible Xoode were installed, and others are experiencing it and
have reported it on the iPhone dev forums. I've been back and forth
with Apple support, but they keep saying they can't reproduce the
problem, which is unfortunate, because I live with it.
- The article is actually about frameworks, which is not possible, so
you actually have to to the drag / reference thing anyway if you have
any project resources like images or NIBs in your static libs.
- I'm not sure I trust the whole situation when it comes to naming
conventions -- but it would seem that the possibility for naming
conflicts might arise quickly.
Verdict -- we'll see. Apple obviously intended use of static libs,
given that there's now an Xcode template for them, but I don't know
all that implies underneath the hood. What I do know is that I've lost
many hours on this stuff...but this raises the question....
How are you linking in third party projects like Facebook Connect?
That was the same kind of issue....
Ok, now this I have to take exception to. Seriously? You have naming conflicts in iPhone projects? I mean, these are NOT large projects (or they shouldn't be).
In fact, I can really only think of one case in my entire career that I have had a naming conflict, and in that case, yes, it was for two classes that were functionally the same, one written by me, another by another coder. The solution? Of course to merge them and make one class. Which is exactly what you SHOULD do.