Subclassing NSOperation to be concurrent and cancellable

Okay, so as I understand it, you have two questions: Do you need the performSelectorOnMainThread: segment that appears in comments in your code? What does that code do? Why is the _isCancelled flag is not modified when you call cancelAllOperations on the NSOperationQueue that contains this operation? Let’s deal with these in order. I’m going … Read more

iOS – How to implement a performSelector with multiple arguments and with afterDelay?

Personally, I think that a closer solution to your needs is the use of NSInvocation. Something like the following will do the work: indexPath and dataSource are two instance variables defined in the same method. SEL aSelector = NSSelectorFromString(@”dropDownSelectedRow:withDataSource:”); if([dropDownDelegate respondsToSelector:aSelector]) { NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[dropDownDelegate methodSignatureForSelector:aSelector]]; [inv setSelector:aSelector]; [inv setTarget:dropDownDelegate]; [inv setArgument:&(indexPath) atIndex:2]; … Read more

Alternative to performSelector in Swift?

Using closures class A { var selectorClosure: (() -> Void)? func invoke() { self.selectorClosure?() } } var a = A() a.selectorClosure = { println(“Selector called”) } a.invoke() Note that this is nothing new, even in Obj-C the new APIs prefer using blocks over performSelector (compare UIAlertView which uses respondsToSelector: and performSelector: to call delegate methods, … Read more