Mac Finding invalid method names?

robvas

macrumors 68030
Original poster
Mar 29, 2009
2,801
372
USA
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

Is there a compiler option that will turn on stricter checking of method names? just spent 25 minutes tracking a bug down and it ended up being a simple case of using numberofObjects instead of numberOfObjects with an NSArray.
 

xStep

macrumors 68010
Jan 28, 2003
2,001
98
Less lost in L.A.
According to a documentation search, the numberOfObjects method is associated with the NSFetchedResultsSectionInfo Protocol. NSArray uses the count method.

In both Xcode 3 and 4, a warning is issued on the line where I misspelled the method name. Perhaps I've turn a warning on, or you turned a warning off.
 

gnasher729

macrumors P6
Nov 25, 2005
16,532
3,129
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

Is there a compiler option that will turn on stricter checking of method names? just spent 25 minutes tracking a bug down and it ended up being a simple case of using numberofObjects instead of numberOfObjects with an NSArray.
Go to project settings, look at the setting "compiler warnings", turn on each warning in turn and keep everything that looks useful. Most important "treat warnings as errors".

Also there is no checking when sending a message to an object with declared type "id", so sometimes you have to assign to the right type first.
 

Oligarch

macrumors newbie
Nov 10, 2008
17
0
Also, use code completion. It is tremendously faster than manually spelling out long method names and pretty much eliminates typos like this one. Works for anything: class names, method names, named constants, variables, functions. The built-in heuristics are quite good. You don't even have to respect capitalization. Just type the first few letters in lower case and hit escape, then return or the next character, like a space, semicolon, etc. Nine times out of ten, it should give you what you want, no need to pause and select, guaranteed typo-free. If it does get it wrong, Cmd-Z and add another couple of letters, or select from the list.