首页 > 代码库 > 小白学开发(iOS)OC_ SEL数据类型(2015-08-10)

小白学开发(iOS)OC_ SEL数据类型(2015-08-10)

//

//  main.m

//  SEL数据类型

//

//  Created by admin on 15/8/12.

//  Copyright (c) 2015 admin. All rights reserved.

//


#import <Foundation/Foundation.h>

#import "Person.h"

/*

    SEL数据类型,使用来包装方法的

 */


int main(int argc,const char * argv[]) {

    @autoreleasepool {

//  使用@selector就行把一个方法包装成 SEL数据类型

        

       Person *p = [[Personalloc]init];

       SEL s1 = @selector(eat);

        [pperformSelector:s1];

        

       SEL s2 = @selector(call:);

        [p performSelector:s2withObject:@"1519387554"];

        

       SEL s3 = @selector(findName);

       NSString *result = [p performSelector:s3];

       NSLog(@"%@",result);

        

    }

   return 0;

}

//

//  Person.h

//  OC的特有语法

//

//  Created by admin on 15/8/12.

//  Copyright (c) 2015 admin. All rights reserved.

//


#import <Foundation/Foundation.h>


@interface Person :NSObject


- (void)eat;

- (void)call:(NSString *)number;

- (NSString *)findName;

@end


//

//  Person.m

//  OC的特有语法

//

//  Created by admin on 15/8/12.

//  Copyright (c) 2015 admin. All rights reserved.

//


#import "Person.h"


@implementation Person


- (void)eat

{

   NSLog(@"吃东西");

}

- (void)call:(NSString *)number

{

   NSLog(@"打电话给 %@",number);

}

- (NSString *)findName

{

    return@"找到了腾格尔";

}

@end



小白学开发(iOS)OC_ SEL数据类型(2015-08-10)