C19_OC09-方法的类型SEL

#import <Foundation/Foundation.h>

@interface Persion : NSObject
- (void) test;
@end

@implementation Persion
- (void) test{
    // _cmd是一个SEL类型的常量,保存当前方法地址。每个方法都内置这个属性
    // 如同: SEL _cmd = @selector(test);
    NSLog(@"还是SEL牛逼,_cmd:%@", NSStringFromSelector(_cmd));
    
    // [self performSelector:_cmd]; //死循环
}
@end

int main(){
    // 1.分配内存
    // 除了成员变量,还有SEL类型的属性,保存方法的内存地址
    Persion * p = [[Persion alloc] init];
    
    // 2.这里首先把test封装为SEL类型的数据
    // 然后到类中匹配已有的SEL数据
    // 如果找到了,就根据地址调用
    [p test];
    
    // 3.上一步在与类中的SEL数据匹配成功后,会保存一份缓存
    // 如果再次调用test,直接从缓存取地址,不再去类中匹配
    
    //这一句,XCode5.1报错:Multiple methods named 'test' dound with mismatched result, parameter type or attributes.
    //[p performSelector:@selector(test)];  //下面的分开写却没事了(估计是XCode的bug,因为在终端使用cc运行无误)
    SEL s1 = @selector(test);
    [p performSelector:s1]; // 但XCode在这里报警:PerformSelector may cause a leak because its selector is unknown
    
    // 如果已知方法名,可以随时切换要调用的方法
    NSString * fuc = @"test";
    SEL s2 = NSSelectorFromString(fuc);
    // [p fuc];  // 这是不行的
    [p performSelector:s2]; // XCode报警
    
    return 0;
}

- end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR: Command errored out with exit status 1: command: 'D:\personal_center_p3\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\V_YXYU~1\\AppData\\Local\\Temp\\pip-install-j9hkssrc\\concurrentloghandler_c01cddb927a545c19eaf92b46c24b0aa\\setup.py'"'"'; __file__='"'"'C:\\Users\\V_YXYU~1\\AppData\\Local\\Temp\\ pip-install-j9hkssrc\\concurrentloghandler_c01cddb927a545c19eaf92b46c24b0aa\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\V_YXYU~1\AppData\Local\Temp\pip-pip-egg-info-lysncohs' cwd: C:\Users\V_YXYU~1\AppData\Local\Temp\pip-install-j9hkssrc\concurrentloghandler_c01cddb927a545c19eaf92b46c24b0aa\ Complete output (1 lines): error in ConcurrentLogHandler setup command: use_2to3 is invalid. ---------------------------------------- WARNING: Discarding https://files.pythonhosted.org/packages/fd/e5/0dc4f256bcc6484d454006b02f33263b20f762a433741b29d53875e0d763/ConcurrentLogHandler-0.9.1.tar.gz#sha256=8225a590fd4194c413fa26675bde5f6b80ad79e4182d5876ba3e264f77755918 (from https://pypi.org/simple/concurrentloghandler/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. ERROR: Could not find a version that satisfies the requirement ConcurrentLogHandLer==0.9.1 (from versions: 0.7.2, 0.7.3, 0.7.4, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.8.5, 0.8.6, 0.8.7, 0.9.0, 0.9.1) ERROR: No matching distribution found for ConcurrentLogHandLer==0.9.1
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值