views:

78

answers:

2

A general question on style and best practices...

I have an ObjC controller object.

After alloc/init of the object, I get it to do a job asynchronously:

[myObject doSomeThingsOverTime];

The method sets things in motion, and then returns immediately.

Question: what is the best way to be notified of the result in the future, so that I can release myObject and react to the work having been completed? Should I observe/post notifications? Or supply the object with a method to callback? Or other? Thanks for any help.

+2  A: 

I'm personally a fan of the notification center route. It allows for more than one observer (may or may not be relevant to you).

The delegate route is also valid, and is used quite frequently in the frameworks.

I think it comes down to personal preference. If it's your own code, you should go for what's most readable and simple for your particular situation. I don't think one is more or less valid than the other.

NilObject
Thanks! I'll stick with Notifications then. Cheers.
SirRatty
+1  A: 

Have you looked at the NSOperation and NSOperationQueue classes? You can observe the isFinished of an NSOperation object so you will get notified when it is completed.

Diederik Hoogenboom