Re:Cargo-cult typing, or: Objective-C's default type is id
by mpweiher on Thursday March 06, 2014 @02:45AM
(#7352423)
You could just write:
id color = [UIColor green];
id viewController = [[MyViewController alloc] initWithBackgroundColor:color];
The UIColor* is largely there for your benefit, for the compiler it makes hardly a difference (pre ARC). If you don't find it a benefit, just leave it out.
I wish Apple would add local type inference to Objective-C, perhaps using the existing id type or some keyword like var in C#. It would make the code so much more quicker to write, less verbose, a bit easier to change.
I mean reading and writing something like:
Is so much more pleasant as: