OC SEL
来源:互联网 发布:淘宝美工培训机构 编辑:程序博客网 时间:2024/05/19 16:19
//// Person.h// SEL//// Created by LiuWei on 15/4/15.// Copyright (c) 2015年 LiuWei. All rights reserved.//#import <Foundation/Foundation.h>
@interface Person : NSObject- (void)test;- (void)test2;- (void)test3withStr1:(NSString*)str;@end
//// Person.m// SEL//// Created by LiuWei on 15/4/15.// Copyright (c) 2015年 LiuWei. All rights reserved.//#import "Person.h"@implementation Person- (void)test{ // 每个对象方法内部都有一个隐藏的 _cmd 代表当前方法 // NSStringFromSelector(SEL) 把选择器转换成字符串 NSString *str = NSStringFromSelector(_cmd); NSLog(@"_cmd --- %@", str); NSLog(@"Person --- test");}- (void)test2{ NSLog(@"Person --- test2");}- (void)test3withStr1:(NSString *)str{ NSLog(@"%@", str);}@end
//// main.m// SEL//// Created by LiuWei on 15/4/15.// Copyright (c) 2015年 LiuWei. All rights reserved.//#import <Foundation/Foundation.h>#import "Person.h"// 每个类的方法列表都存储在类对象中// 第个方法都有一个与之对应的SEL数据int main(){ Person *p = [[Person alloc]init]; // 调用test方法时会把方法名 test包装成 SEL类型数据 // 根据SEL类型数据找到方法地址 // 根据方法地址,调用相应方法 [p test]; /// An opaque type that represents a method selector. // typedef struct objc_selector *SEL; [p performSelector:@selector(test2)]; [p performSelector:@selector(test3withStr1:) withObject:@"hahaha!"]; NSString * str = @"test2"; SEL s = NSSelectorFromString(str); [p performSelector:s]; return 0;}
- (id)performSelector:(SEL)aSelector
Description
Sends a specified message to the receiver and returns the result of the message. (required)
The performSelector: method is equivalent to sending anaSelector message directly to the receiver. For example, all three of the following messages do the same thing:
id myClone = [anObject copy];
id myClone = [anObject performSelector:@selector(copy)];
id myClone = [anObject performSelector:sel_getUid("copy")];
However, the performSelector: method allows you to send messages that aren’t determined until runtime. A variable selector can be passed as the argument:
SEL myMethod = findTheAppropriateSelectorForTheCurrentSituation();
[anObject performSelector:myMethod];
The aSelector argument should identify a method that takes no arguments. For methods that return anything other than an object, useNSInvocation.
Parameters
aSelector
A selector identifying the message to send. If aSelector is NULL, anNSInvalidArgumentException is raised.
Returns
An object that is the result of the message.
Availability
OS X (10.0 and later)
Declared In
NSObject.h
Reference
NSObject Protocol Reference
NSString * NSStringFromSelector (
SEL aSelector
);
Description
Returns a string representation of a given selector.
Parameters
aSelector
A selector.
Returns
A string representation of aSelector.
Availability
OS X (10.0 and later)
Declared In
NSObjCRuntime.h
Reference
Foundation Functions Reference
- (id)performSelector:(SEL)aSelector withObject:(id)anObject
Description
Sends a message to the receiver with an object as the argument. (required)
This method is the same as performSelector: except that you can supply an argument foraSelector.aSelector should identify a method that takes a single argument of typeid. For methods with other argument types and return values, useNSInvocation.
Parameters
aSelector
A selector identifying the message to send. If aSelector is NULL, anNSInvalidArgumentException is raised.
anObject
An object that is the sole argument of the message.
Returns
An object that is the result of the message.
Availability
OS X (10.0 and later)
Declared In
NSObject.h
Reference
NSObject Protocol Reference
SEL NSSelectorFromString (
NSString *aSelectorName
);
Description
Returns the selector with a given name.
To make a selector, NSSelectorFromString passes a UTF-8 encoded character representation ofaSelectorName tosel_registerName and returns the value returned by that function. Note, therefore, that if the selector does not exist it is registered and the newly-registered selector is returned.
Recall that a colon (“:”) is part of a method name;setHeight is not the same assetHeight:.
Parameters
aSelectorName
A string of any length, with any characters, that represents the name of a selector.
Returns
The selector named by aSelectorName. IfaSelectorName isnil, or cannot be converted to UTF-8 (this should be only due to insufficient memory), returns(SEL)0.
Availability
OS X (10.0 and later)
Declared In
NSObjCRuntime.h
Reference
Foundation Functions Reference
- OC SEL
- OC语言--SEL
- oc中的选择器SEL
- OC-SEL类型
- OC-033.SEL类型
- oc 中的SEL
- OC中description和SEL
- OC语言--SEL类型小记
- OC中的description和sel
- OC语言SEL和description
- OC特有语法—SEL
- OC - SEL类型的使用
- OC基础-SEL解析14
- OC-@class, SEL , IMP等灵活机制
- OC基础—description方法、SEL类型
- 黑马视频学习笔记-OC-SEL
- OC语言description方法和sel
- oc - 6 description NSLog(扩展) SEL
- 希腊字母手写笔顺
- CSS+DIV布局注意事项
- windows游戏编程 以PeekMessage为核心的消息循环体系
- 3.24
- Error: Dynamic is undefined
- OC SEL
- Android多媒体浅析
- linux成长之路(makefile快速入门)
- 迭代算法
- 采用漏桶算法和令牌桶算法实现限流技术
- OSPF-LSA系列—LSA TYPE 2
- Qt on Android:添加分享功能
- 一个基于protocol buffer的RPC实现
- 广度优先搜索和深度优先搜索