PDA

View Full Version : callback handlers ( one O one)




mdeh
Feb 14, 2009, 02:15 AM
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.



gnasher729
Feb 14, 2009, 07:00 AM
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.

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?

lee1210
Feb 14, 2009, 08:08 AM
The docs are always a good place to start. They are also available online. Here is the relevant link:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsfilemanager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/removeFileAtPath:handler:

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:
http://en.wikipedia.org/wiki/Callback_(computer_science)

-Lee

mdeh
Feb 14, 2009, 08:33 AM
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:
http://en.wikipedia.org/wiki/Callback_(computer_science)

-Lee


thank you so much Lee...appreciated....the wiki was quite instructive.
Lee...as 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.

kalimba
Feb 14, 2009, 10:25 AM
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?

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.