I am developing a class that will "fire events" whenever something happens. These events are generally not UI related. I am wondering what is the best way to do this? I studied either:
Delegates
I define the delegate class, accept the delegate in the init function, and call the methods in the delegate class when an event occurs.
C-style blocks
I define a pointer to a function and accept the function in the init function. I will call it when the event happens.
In both cases, I may need to process several "sources", so I need an array of delegates or blocks.
I noticed that in iOS programming, delegates tend to prefer especially for user interface interfaces. But I come from functional programming, where Iβm definitely comfortable taking function points and skipping lambdas at the call site, and I like that the compiler handles dragging variables for you, and you usually need a smaller class state. But I see that many iOS developers use delegates.
What is the generally preferred mechanism in iOS for this?
c lambda ios objective-c delegates
tng
source share