I am designing a class that will \"fire events\" whenever something occurs. These events tend to be non-UI related. I\'m wondering what the best method for doing so is. I\'ve be
Each has its use.
Delegates should be used when there are multiple "events" to tell the delegate about and/or when the class needs to get data from the delegate. A good example is with UITableView
.
A block is best used when there is only one (or maybe two) event. A completion block (and maybe a failure block) are a good example of this. A good example is with NSURLConnection sendAsynchronousRequest:queue:completionHandler:
.
A 3rd option is notifications. This is best used when there are possibly multiple (and unknown) interested parties in the event(s). The other two are only useful when there is one (and known) interested party.