callback handlers ( one O one)

Discussion in 'Mac Programming' started by mdeh, Feb 14, 2009.

  1. macrumors 6502

    Jan 3, 2009
    I have been unable to find a nice article on the essence of callback handlers.

    So, for instance, it is introduced on p 378 of Kochan 2.0.

    Eg -(BOOL) removeFileAtPath:handler:

    I would just like to understand why passing "nil" as an argument returns "NO" if the return type is BOOL, and what else one could do, if "nil" is not passed. Not in detail, but just in very general principles.
    Thank you in advance.
  2. macrumors G5


    Nov 25, 2005
    Have you opened XCode, selected "Documentation" from the menu and typed in "removeFilatAtPath" ? If not, do it. If yes, what exactly is it in that documentation that you don't understand?
  3. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    The docs are always a good place to start. They are also available online. Here is the relevant link:

    This method should only return NO when handler is nil if the file cannot be deleted. If the file can be deleted, YES should be returned. The handler that is passed in only comes into play IF the file cannot be deleted. At that point, the message
    - (BOOL)fileManager:(NSFileManager *)manager shouldProceedAfterError:(NSDictionary *)errorInfo
    will be sent to the handler object. The return value of this method will be returned instead of NO.

    The general idea of a callback is giving power to a developer using a predefined method to alter its behavior at runtime by passing in a method pointer or object pointer that the predefined method can use in its execution. I don't know if you already read the wikipedia entry on this, but it provides a pretty good explanation:

  4. thread starter macrumors 6502

    Jan 3, 2009

    thank you so much Lee...appreciated....the wiki was quite instructive. you can see I am still very much new at this...but I do recall that in the section on function pointers in K&R, there was a "sort -of " call back used. {they used a modified quick sort and passed the function pointer to one of 2 functions, depending upon whether 2 integers or 2 strings were being compared. The result of course was a sort -method taking it's very first baby steps to becoming independent of the sorted data.
  5. macrumors regular

    Jun 10, 2008
    I have to agree that the docs are the FIRST place I look when something is unclear to me or needs qualification. Option-double-click has become my best friend in Xcode, as you can option-double-click on any symbol in your source code and Xcode will automatically take you to the documentation and search for that symbol.

Share This Page