Make Xcode 4.3 warn about undeclared methods that exist in the current @implementation
Asked Answered
K

3

9

Xcode 4.3 doesn't warn about undeclared methods when they exist in the current @implementation, which is a great new feature. However, this is causing an issue in certain circumstances when using my project on Xcode 4.2.

How do I re-enable the warnings for undeclared methods?

For example:

@interface MashTun : NSObject
- (void)foo;
@end

@implementation MashTun
- (void)foo {
    CGRect rect = [self smallRect];
    NSLog(@"My Small Rect: %@", NSStringFromCGRect(rect));
}

- (CGRect)smallRect {
    return CGRectMake(0, 0, 100, 100);
}
@end

In Xcode 4.2, this fails:

warning: instance method '-smallRect' not found (return type defaults to 'id')
error: initializing 'CGRect' (aka 'struct CGRect') with an expression of incompatible type 'id' 

I completely understand the warning and error in Xcode 4.2 since it's not allowing the search for methods within the current @implementation scope. (The fix is simple: either put the smallRect method above the foo method, or declare the smallRect method in a category or the header. )

But how do I turn on a warning in Xcode 4.3 to catch this error before passing it on to colleagues running 4.2?

Karnes answered 5/3, 2012 at 1:37 Comment(8)
I've not got 4.3 installed yet but is there still the option under Build Settings for Undeclared Selector? does this have any effect?Juarez
You'd think so by the name --but that is referring to using @selector(foo) and whether it checks for an existing method by that name.Karnes
Yeah, this is a great advance in 4.3, and at the same time a bit of a hassle. It burns me regularly. The good news is that it won't be too long before the problem goes away with everyone upgrading (and we can finally stop pre-declaring methods unnecessarily).Freshet
@RobNapier Is there a way to use the same version of LLVM in 4.2 successfully in 4.3?Karnes
Almost certainly. I build with the old gcc-4.0 and the 10.4 SDK for PPC by lots of symlinking. But for your situation there's no reason to do that. Download the 4.2 Xcode and install it in a different directory and just run it. I have Xcode 3, Xcode 4.2 and Xcode 4.3 all installed at the same time.Freshet
good point, I did the same up until 4.3Karnes
Got the same problem here, with an older machine server-side that uses Hudson (with an old Xcode/compiler) to build the project at each SVN commit… Very interest to have Xcode 4.5 warn me about undeclared method even if it compiles fine, so I can see the missing declarations before commiting to SVN and before the Hudson build fails and force me to do another commit for such a stupid reason…Photomap
I haven't come up with a good solution for this. My advice is to use the same version across all developers and the Hudson machine. If Hudson is fixed on an older version, you may have to stay on that version until you can upgrade Hudson.Karnes
S
0

The new LLVM 3.1 compiler does not care about this. It does not matter if you place the method above/below or whether there is a prototype. So if all your colleagues have their Xcode updated to at least 4.3. This really should not be an issue.

Another option is to create your own warning using the code below. You cold inform them of this issue, and problem at hand. This might be an easy way to get the message across.

#warning "warning message"

Hope this helps.

Stretto answered 14/3, 2012 at 1:37 Comment(3)
Thanks, I am aware the LLVM 3.1 doesn't warn about these and that my colleagues could upgrade. This is not currently possible. What I'd like is to see these warnings for myself before handing the project to them. Creating an error manually would assume that I can see the warnings in 4.3 -- I cannot. Is there a compiler setting to revert to the old behavior?Karnes
You can go through all the warnings, which I have and there is not which is why I suggested the above.Stretto
The previous response I ment you can go through all the compiler warning settings and there is not a flag for that. So this is not possible, either downgrade to Xcode 4.2 or make sure all code you write, for every custom method there is a prototype, which is good practice anyway.Stretto
P
0

I don't know If I might have a funny build but my LLVM 3.1 Compiler does have the Undeclared Selector Flag under the Compiler Warnings. Currently running 4.3.2. the LLVM 4.0 does not have it though.

Pacificism answered 10/7, 2012 at 16:25 Comment(1)
undeclared selector is awesome! But not exactly what i'm talking about. What undeclared selector does is make sure when you do a @selector(foo:) that the selector is valid (at compile time). It's turned off because you could potentially have a dynamic selector at runtime.Karnes
S
0

one option during such a transition would be to cross-compile with another compiler/version. gcc-llvm is one common, preinstalled alternative. another approach would be to install multiple versions of xcode and build using that toolchain.

Sayles answered 10/7, 2012 at 18:33 Comment(1)
yes, and the app-based Xcodes make this easy now. In this case the solution was to upgrade our build server to Lion and just use 4.3 on all stations. Not the solution I was looking for (compiler warning flag) but it worked in the end.Karnes

© 2022 - 2024 — McMap. All rights reserved.