selector

List selectors for Objective-C object

半世苍凉 提交于 2019-11-26 18:32:03
I have an object, and I want to list all the selectors to which it responds. It feels like this should be perfectly possible, but I'm having trouble finding the APIs. This is a solution based on the runtime C functions: class_copyMethodList returns a list of class methods given a Class object obtainable from an object. #import <objc/runtime.h> [..] SomeClass * t = [[SomeClass alloc] init]; int i=0; unsigned int mc = 0; Method * mlist = class_copyMethodList(object_getClass(t), &mc); NSLog(@"%d methods", mc); for(i=0;i<mc;i++) NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i])))

SEL performSelector and arguments

扶醉桌前 提交于 2019-11-26 17:28:52
It seems like there should be an easy way to call a selector with some arguments when all you have is a SEL object. I can't seem to find the correct syntax. -(MyClass*) init: (SEL)sel owner:(NSObject*) parent { int i =10; [parent performSelector:sel:i ]; } Take a look at the NSObject documentation. In this case: [parent performSelector:sel withObject:[NSNumber numberWithInt:i]]; (note this method is actually listed in the NSObject protocol documentation). Since -[NSObject performSelector:withObject:] requires an object argument, you will have to write a wrapper in parent's class like -(void

Java NIO client

烂漫一生 提交于 2019-11-26 17:24:40
问题 import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.*; public class EchoServer { private InetAddress addr; private int port; private Selector selector; private Map<SocketChannel,List<byte[]>>

Objective-C: Calling selectors with multiple arguments

我的梦境 提交于 2019-11-26 15:41:48
In MyClass.m, I've defined - (void) myTest: (NSString *) withAString{ NSLog(@"hi, %@", withAString); } and the appropriate declaration in MyClass.h . Later I want to call [self performSelector:@selector(mytest:withAString:) withObject: mystring]; in MyClass.m but I get an error similar to * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[MyClass myTest:withAtring:]: unrecognized selector sent to instance 0xe421f0' I tried a simpler case with a selector that took no arguments that printed a string to console and that worked just fine. What's wrong with the

Selectors in Objective-C?

烂漫一生 提交于 2019-11-26 15:08:41
问题 First, I'm not sure I really understand what a selector is. From my understanding, it's the name of a method, and you can assign it to a class of type 'SEL' and then run methods such as respondToSelector to see if the receiver implements that method. Can someone offer up a better explanation? Secondly, to this point, I have the following code: NSString *thing = @"Hello, this is Craig"; SEL sel = @selector(lowercaseString:); NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO")

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

JQuery $(this) selector function and limitations

烂漫一生 提交于 2019-11-26 14:11:59
问题 I need help understanding $(this). Is it possible to narrow the focus of 'this' within the parentheses or does "this" preclude the use of any other attributes? For example: I don't understand why this code: $(this).children("div") can't be rewritten like this: $(this +" div") without having to resort to something like: $('#'+$(this).attr("id")+" div") Also, can you point me to 'this' in the JQuery documentation? It is difficult to use 'this' as a search term for obvious reasons. 回答1: this isn

jQuery - How to select value by attribute name starts with

坚强是说给别人听的谎言 提交于 2019-11-26 12:19:41
问题 I want to select attribute value by giving attribute name (only starts with) For instance if we have html tag <div class = \"slide\" data-confirmID = \"46\" confirmID = \"54\"/> I want to select the value from the attribute starts with data- Thanks in advance for the help. 回答1: If you want all data-* attributes, you can iterate through jq data object: $('.slide').each(function(){ for(data in $(this).data()) console.log(data); // returns confirmID so element as an attribute `data-confirmID` })

Why must the last part of an Objective-C method name take an argument (when there is more than one part)?

痞子三分冷 提交于 2019-11-26 11:49:27
问题 In Objective-C, you can\'t declare method names where the last component doesn\'t take an argument. For example, the following is illegal. -(void)take:(id)theMoney andRun; -(void)take:(id)yourMedicine andDontComplain; Why was Objective-C designed this way? Was it just an artifact of Smalltalk that no one saw a need to be rid of? This limitation makes sense in Smalltalk, since Smalltalk doesn\'t have delimiters around message invocation, so the final component would be interpreted as a unary

What&#39;s the difference between a method and a selector?

一个人想着一个人 提交于 2019-11-26 11:47:39
问题 What the difference between a method, a selector and a message in Objective-C? 回答1: This is a great question. Selector - a Selector is the name of a method. You're very familiar with these selectors: alloc , init , release , dictionaryWithObjectsAndKeys: , setObject:forKey: , etc. Note that the colon is part of the selector; it's how we identify that this method requires parameters. Also (though it's extremely rare), you can have selectors like this: doFoo::: . This is a method that takes