Dealing with the lack of closures in Objective-C
Posted
by Sean Clark Hess
on Stack Overflow
See other posts from Stack Overflow
or by Sean Clark Hess
Published on 2010-03-22T18:08:05Z
Indexed on
2010/03/22
18:11 UTC
Read the original article
Hit count: 590
Maybe it's just the fact that I've been using http://nodejs.org/ lately, but the lack of closures in Objective-C (iphone) has been really hard to work around.
For example, I'm creating service classes. Each service class can have several methods, each of which makes a different URL request. I can use the delegate pattern, but that means that I have to create a new service each time I want to call a method on it (because it has to store the delegate and selector for that request, and new method calls would overwrite them).
Even more difficult for me is the fact that I can't easily keep local variables around in the scope for a callback. I have to store anything I want to send back to the delegate on the service class itself, which makes it harder to have more than one method on each class.
How do you pros do it? Should I just quit whining and do it another way?
© Stack Overflow or respective owner