In Objective-C the following code compiles with no warnings:
id obj = [[NSObject alloc] init];
NSString *str = obj;
NSLog(@"%@", str);
While the following code compiles with a pointer assignment warning:
NSObject *obj = [[NSObject alloc] init];
NSString *str = obj;
NSLog(@"%@", str);
Since it is quite a common practice among Cocoa developers to have most init and factory methods return an id, the former scenario arises very easily:
Mammal *animal = [Crocodile animalWithName:@"Croc"]; // Method animalWithName returns id.
For a real world scenario I could refer to Cocos2D for iOS:
CCFiniteTimeAction *walkAction = [CCRepeatForever actionWithAction: action]; // Method actionWithAction returns id.
I agree that CCRepeatForever doesn't sound like a CCFiniteTimeAction (instead, it is a direct subclass of CCAction), but it would be nice to have some help from the compiler. Is there a way for the programmer to have Xcode generate a warning in these cases?