Finding invalid method names?

Discussion in 'Mac Programming' started by robvas, Mar 9, 2012.

  1. robvas macrumors 68030

    Mar 29, 2009
    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.
  2. xStep macrumors 68000

    Jan 28, 2003
    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.
  3. gnasher729 macrumors P6


    Nov 25, 2005
    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.
  4. Oligarch macrumors newbie

    Nov 10, 2008
    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.

Share This Page