Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
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

Suspended
Nov 25, 2005
17,980
5,566
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

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
The docs are always a good place to start. They are also available online. Here is the relevant link:
http://developer.apple.com/document...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
Code:
- (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

macrumors 6502
Original poster
Jan 3, 2009
345
2
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

macrumors regular
Jun 10, 2008
102
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.