6

I noticed that Xcode (or more precisely the Apple LLVM compiler?) does not longer require forward method declarations. In other words, the following code builds without warnings:

@implementation Foo

-(void) foo {
    [self bar];
}

-(void) bar {}

@end

This used to throw a warning in -foo saying that Foo might not respond to -bar, right? Is the compiler smarter now or is this something else? I’m using Xcode 4.3.1 plus Apple LLVM compiler 3.1.

zoul
  • 102,279
  • 44
  • 260
  • 354

2 Answers2

2

This has definitely changed, and it looks like such forward declarations are not required in Xcode 4.3 & later. Cf. Private Methods in Objective-C, in Xcode 4.3 I no longer need to declare them in my implementation file ?.

Community
  • 1
  • 1
Clay Bridges
  • 11,602
  • 10
  • 68
  • 118
0

In my XCode 4.2, the warning is still there, moreover, when ARC is enabled, it is an error, not just a warning.

hamstergene
  • 24,039
  • 5
  • 57
  • 72
  • Not if you call and implement the method in the same file. If he'd done [foo bar] from another file, it would error, but it seems fine in the situation above. – jrturton Mar 27 '12 at 07:48
  • @jrturton I have it implemented right below in the same file and it is still an error. – hamstergene Mar 27 '12 at 07:49
  • 2
    Try in 4.3? I've noticed this too, I think it's a compiler feature – jrturton Mar 27 '12 at 07:51