IOS 6.0 xcode 4.5 compilation errors #import code held in files outside of the class

岁酱吖の 提交于 2020-01-03 03:08:06

问题


I've been happily compiling and going my merry way with Xcode 4.3.2 (IOS5.1). Now that I've taken the plunge and decided to move to Xcode 4.5 my App fails compilation in a most miserable manner. Now, I've not got past the issue with ARMV7 or anything like that yet. No. My issue is probably going to make many of you groan.

But you can blame my basic ANSI C days for that. Everyone likes reusable code and I've created lots of it. BUT!!! I've not made any of this particular code into object(s) per se. That is, I've not taken the steps of the Interface and Implementation to heart.

Sure, I have my classes for my view controllers etc. But, to save having to declare and alloc *init* objects so I can use the methods therein, I've simply dumped a load of methods into a .inc file - in other words an include file. E.g, I'd have a method for altering the background colour or background image a of a table cell - and I'd import the file that had the method that did it.

E.g.

-(void)defaultInactiveBackGroundForCell:(UITableViewCell *)cell {

   cell.backgroundView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:DEFAULT_INACT_CELL_BACKGROUND_IMAGE] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];

} // defaultInactiveBackGroundForCell

All well and good so far.

And, I'd #import the file (containing the above code) at the top of my class file, my .m file. In my willDisplayCell delegate method, i'd simply call the following method:

[self defaultInactiveBackGroundForCell:cell];

And it'd work.

But under Xcode 4.5 it's kicking off big time:

Missing contact for method in declaration.

So, my question is: Is there any way at all of #importing code into a class .m fill like we used to do in the old days with ANSI C?

Help ?


回答1:


I think I know what the problem might be. The methods that I'm importing are fully implemented, that is, they're not headers. These full methods are #imported after my @implementation line.

I added the method spec, in the form of a .h file as a private class inbetween my @interface and my @end as part of a private method declaration within the @implementation.

I'm perhaps not making sense but essentially, Xcode 4.3.2 seemed to be happy to have all of these methods import in between the @implementation and @end. But Xcode 4.5 utterly does not. It requires the headers defined too.




回答2:


I'm not sure that it's related to your 'Object Orientation' or lack there of. As of Xcode 4.5, the minimum deployment target is iOS 4.3. I had a header import error on a recent project after migrating to Xcode 4.5 where my deployment target was 4.0. Changing that to 4.3 fixed it.



来源:https://stackoverflow.com/questions/12609963/ios-6-0-xcode-4-5-compilation-errors-import-code-held-in-files-outside-of-the-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!