performselector

Return value for performSelector:

痞子三分冷 提交于 2019-11-27 10:46:12
问题 What will the return value for performSelector: if I pass a selector that returns a primitive type (on object), such as 'week' on NSDateComponents (which will return an int)? 回答1: 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

PerformSelector warning

主宰稳场 提交于 2019-11-27 01:57:39
问题 I'm receiving a warning PerformSelector may cause a leak because its selector is unknown In the code: - (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err { assert([NSThread isMainThread]); if([delegate respondsToSelector: selector]) { if(arg != NULL) { //this line the warning [delegate performSelector: selector withObject: arg withObject: err]; } else { //this line the warning [delegate performSelector: selector withObject: err]; } } else { NSLog(@"Missed Method"); }

Swift alternative to performSelectorOnMainThread

假如想象 提交于 2019-11-26 16:50:41
问题 I want to reload my table data inside a block in this method: import UIKit import AssetsLibrary class AlbumsTableViewController: UITableViewController { var albums:ALAssetsGroup[] = [] func loadAlbums(){ let library = IAAssetsLibraryDefaultInstance library.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupAll), usingBlock: {(group, stop) in if group { self.albums.append(group) } else { dispatch_async(dispatch_get_main_queue(), { self.tableView.reloadData() }) } }, failureBlock: { (error

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

折月煮酒 提交于 2019-11-26 15:06:35
I am an iOS newbie. I have a selector method as follows - - (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second { } I am trying to implement something like this - [self performSelector:@selector(fooFirstInput:secondInput:) withObject:@"first" withObject:@"second" afterDelay:15.0]; But that gives me an error saying - Instance method -performSelector:withObject:withObject:afterDelay: not found Any ideas as to what I am missing? valvoline Personally, I think that a closer solution to your needs is the use of NSInvocation. Something like the following will do the work: indexPath

Subclassing NSOperation to be concurrent and cancellable

a 夏天 提交于 2019-11-26 12:35:09
问题 I am unable to find good documentation about how to subclass NSOperation to be concurrent and also to support cancellation. I read the Apple docs, but I am unable to find an \"official\" example. Here is my source code : @synthesize isExecuting = _isExecuting; @synthesize isFinished = _isFinished; @synthesize isCancelled = _isCancelled; - (BOOL)isConcurrent { return YES; } - (void)start { /* WHY SHOULD I PUT THIS ? if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector

Alternative to performSelector in Swift?

心不动则不痛 提交于 2019-11-26 11:48:43
The performSelector family of methods are not available in Swift . So how can you call a method on an @objc object, where the method to be called is chosen at runtime, and not known at compile time? NSInvocation is apparently also not available in Swift. I know that in Swift, you can send any method (for which there is an @objc method declaration visible) to the type AnyObject , similar to id in Objective-C. However, that still requires you to hard-code the method name at compile-time. Is there a way to dynamically choose it at runtime? Using closures class A { var selectorClosure: (() -> Void

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

冷暖自知 提交于 2019-11-26 05:58:08
问题 I am an iOS newbie. I have a selector method as follows - - (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second { } I am trying to implement something like this - [self performSelector:@selector(fooFirstInput:secondInput:) withObject:@\"first\" withObject:@\"second\" afterDelay:15.0]; But that gives me an error saying - Instance method -performSelector:withObject:withObject:afterDelay: not found Any ideas as to what I am missing? 回答1: Personally, I think that a closer

Alternative to performSelector in Swift?

醉酒当歌 提交于 2019-11-26 02:20:51
问题 The performSelector family of methods are not available in Swift. So how can you call a method on an @objc object, where the method to be called is chosen at runtime, and not known at compile time? NSInvocation is apparently also not available in Swift. I know that in Swift, you can send any method (for which there is an @objc method declaration visible) to the type AnyObject , similar to id in Objective-C. However, that still requires you to hard-code the method name at compile-time. Is