成免费crm特色大爆料,青岛做优化网站哪家好,wordpress 邮件,网站开发图书管理系统performSelector方法performSelector在运行时#xff0c;调用方去找目标方法selector#xff0c;在编译时不做校验#xff1b;延迟执行 -- 与RunLoop有关调用performSelector:withObject:afterDelay方法实现延迟执行#xff0c;底层的本质是会创建NSTimer定时器去执行目标方…performSelector方法performSelector在运行时调用方去找目标方法selector在编译时不做校验延迟执行 -- 与RunLoop有关调用performSelector:withObject:afterDelay方法实现延迟执行底层的本质是会创建NSTimer定时器去执行目标方法selector- (void)viewDidLoad { [super viewDidLoad]; [self performSelector:selector(test) withObject:nil afterDelay:3]; } - (void)test { NSLog(%s,__func__); NSLog(%,[NSThread currentThread]); } end在主线程中延迟3秒后执行test方法可以执行成功若将performSelector:withObject:afterDelay方法 放在子线程中调用如下implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ [self performSelector:selector(test) withObject:nil afterDelay:3]; }); } - (void)test { NSLog(%s,__func__); NSLog(%,[NSThread currentThread]); } end在子线程中调用performSelector:withObject:afterDelay方法 是不会执行test方法的因为NSTimer定时器依赖于RunLoop才能执行必须开启子线程的RunLoop做如下修改implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ [self performSelector:selector(test) withObject:nil afterDelay:3]; [[NSRunLoop currentRunLoop] run]; }); } - (void)test { NSLog(%s,__func__); NSLog(%,[NSThread currentThread]); } end开启子线程执行任务 -- 与多线程有关performSelector: onThread:withObject: waitUntilDone: 可指定线程执行目标方法任务implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSLog(%,[NSThread currentThread]); NSLog(11111); [self performSelector:selector(test) onThread:[NSThread currentThread] withObject:nil waitUntilDone:YES]; NSLog(22222); }); } - (void)test { NSLog(%s,__func__); NSLog(%,[NSThread currentThread]); } end控制台的调试结果如下image.pngperformSelector发送消息与消息的执行是处于同一个线程的waitUntilDone参数为Yes表示test方法必须执行完成才会执行之后的打印2222即会阻塞当前线程的继续执行performSelector:方法传递多参数的实现方案第一种方案将所有参数放到字典或者数组中再传递集合即可implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSDictionary *params { name:yanzi, age:30 }; [self performSelector:selector(test:) withObject:params]; } - (void)test:(NSDictionary *)params { NSLog(%--%,params[name],params[age]); } end第二种方案利用objc_msgSend()进行传递其可以传递多个参数#import ViewController.h #import objc/message.h interface ViewController () end implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; ((void (*)(id,SEL,NSString *, NSString *, NSString *))objc_msgSend)(self, selector(testWithParam:param2:param3:),111,222,333); } //有三个参数的方法 - (void)testWithParam:(NSString *)param1 param2:(NSString *)param2 param3:(NSString *)param3 { NSLog(param1:%, param2:%, param3:%,param1, param2, param3); } end第三种方案利用NSInvocation进行传递implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //调用方法 NSArray *paramArray [112,[2,13],12]; [self performSelector:selector(testFunctionWithParam:param2:param3:) withObjects:paramArray]; } //可以传多个参数的方法 - (id)performSelector:(SEL)selector withObjects:(NSArray *)objects{ // 方法签名(方法的描述) NSMethodSignature *signature [[self class] instanceMethodSignatureForSelector:selector]; if (signature nil) { //可以抛出异常也可以不操作。 } //NSInvocation: 利用一个NSInvocation对象包装一次方法调用方法调用者、方法名、方法参数、方法返回值 NSInvocation *invocation [NSInvocation invocationWithMethodSignature:signature]; invocation.target self; invocation.selector selector; //设置参数 NSInteger paramsCount signature.numberOfArguments - 2; // 除self、_cmd以外的参数个数 paramsCount MIN(paramsCount, objects.count); for (NSInteger i 0; i paramsCount; i) { id object objects[i]; if ([object isKindOfClass:[NSNull class]]) continue; [invocation setArgument:object atIndex:i 2]; } //调用方法 [invocation invoke]; //获取返回值 id returnValue nil; if (signature.methodReturnLength) { // 有返回值类型才去获得返回值 [invocation getReturnValue:returnValue]; } return returnValue; } //要调用的方法 - (void)testFunctionWithParam:(NSString *)param1 param2:(NSArray *)param2 param3:(NSInteger)param3 { NSLog(param1:%, param2:%, param3:%ld,param1, param2, param3); } endAI大模型学习福利作为一名热心肠的互联网老兵我决定把宝贵的AI知识分享给大家。 至于能学习到多少就看你的学习毅力和能力了 。我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。一、全套AGI大模型学习路线AI大模型时代的学习之旅从基础到前沿掌握人工智能的核心技能因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获取二、640套AI大模型报告合集这套包含640份报告的合集涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师还是对AI大模型感兴趣的爱好者这套报告合集都将为您提供宝贵的信息和启示。因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获三、AI大模型经典PDF籍随着人工智能技术的飞速发展AI大模型已经成为了当今科技领域的一大热点。这些大型预训练模型如GPT-3、BERT、XLNet等以其强大的语言理解和生成能力正在改变我们对人工智能的认识。 那以下这些PDF籍就是非常不错的学习资源。因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获四、AI大模型商业化落地方案因篇幅有限仅展示部分资料需要点击文章最下方名片即可前往获作为普通人入局大模型时代需要持续学习和实践不断提高自己的技能和认知水平同时也需要有责任感和伦理意识为人工智能的健康发展贡献力量