2019-07-24 performSelector崩溃

2019-07-24  本文已影响0人  我是小胡胡分胡

1、在if中返回bool,可以判断,进入相应分支
2、数值类型,c语言指针类型, 用id或者NSValue等,赋值返回值, 都会崩溃

#import "ViewController.h"
typedef struct astructyp{
    int a;
    char *ptr;
}astructypName;
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //A selector identifying the message to send. The message should take no arguments. If aSelector is NULL, an NSInvalidArgumentException is raised.
    //performSelector方法必须没有参数,并且s方法不能是null或者nil,否则crash
    //Because it can't determine ownership of the returned object at compile-time, ARC makes the assumption that the caller does not need to take ownership, but this may not be true
    //ARC并不知道该方法的返回值是什么,以及该如何处理?该忽略?还是标记为 ns_returns_retained还是
    
    
    NSValue *
    // id
    a1= [self performSelector:@selector(rect1)];
    a1= [self performSelector:@selector(inter)];
    a1= [self performSelector:@selector(charptr)];
    a1= [self performSelector:@selector(restruct)];
    a1= [self performSelector:@selector(retbool)];
    
    
    id
    a2= [self performSelector:@selector(reblock)];
    a2= [self performSelector:@selector(restringObj)];
    
    if ([self performSelector:@selector(retbool)]) {
        NSLog(@"%s-%d %s",__FILE__,__LINE__, __PRETTY_FUNCTION__);
    }else{
        NSLog(@"%s-%d %s",__FILE__,__LINE__, __PRETTY_FUNCTION__);
    }
    
    
    
    NSLog(@"%s-%d %s",__FILE__,__LINE__, __PRETTY_FUNCTION__);
}


-(CGRect)rect1{
    return self.view.frame;
}
-(NSInteger)inter{
    return 1;
}
-(CGFloat)flot{
    return 1.2f;
}
-(BOOL)retbool{
    return NO;
}
-(char *)charptr{
    return "11";
}
-(void(^)(NSString *))reblock{
    return ^(NSString *str){
        return;
    };
}
-(astructypName)restruct{
    astructypName struca;
    struca.a =1;
    struca.ptr="123";
    return struca;
}
-(NSString*)restringObj{
    return @"asdfasdf";
}
@end

上一篇下一篇

猜你喜欢

热点阅读