码迷,mamicode.com
首页 > 其他好文 > 详细

SEL

时间:2015-02-28 21:32:19      阅读:621      评论:0      收藏:0      [点我收藏+]

标签:

//

//  main.m

//  08-SEL

//

//  Created by apple on 13-8-8.

//  Copyright (c) 2013年 itcast. All rights reserved.

//

 

/*

 SEL其实是对方法的一种包装,将方法包装成一个SEL类型的数据,去找对应的方法地址。找到方法地址就可以调用方法

 

 

 其实消息就是SEL

 */

 

#import <Foundation/Foundation.h>

#import "Person.h"

 

int main()

{

    Person *p = [[Person alloc] init];

    

    [p test2];

    

//    NSString *name = @"test2";

//    

//    SEL s = NSSelectorFromString(name);

//    

//    [p performSelector:s];

    

    

    // 间接调用test2方法

    //[p performSelector:@selector(test2)];

    

    //[p test3:@"123"];

    

    

//    SEL s = @selector(test3:);

//    

//    [p performSelector:s withObject:@"456"];

    

    //[p test2];

    

    // 1.把test2包装成SEL类型的数据

    // 2.根据SEL数据找到对应的方法地址

    // 3.根据方法地址调用对应的方法

    return 0;

}

 

SEL

标签:

原文地址:http://www.cnblogs.com/dahongliang/p/4306204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!