Return value for performSelector:

An example of using NSInvocation to return a float: SEL selector = NSSelectorFromString(@”someSelector”); if ([someInstance respondsToSelector:selector]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[someInstance class] instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:someInstance]; [invocation invoke]; float returnValue; [invocation getReturnValue:&returnValue]; NSLog(@”Returned %f”, returnValue); }

How to Wait in Objective-C and Swift

I know I am late to this party. But I found people haven’t mention thread sleep. If you are using GCD to call that function. You can use : NSThread sleepForTimeInterval:2.0f]; to delay the thread for 2 seconds. [self changeText: @”A text”]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //Here your non-main thread. [NSThread sleepForTimeInterval:2.0f]; dispatch_async(dispatch_get_main_queue(), ^{ //Here you … 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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)