//
// 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 = [[Person alloc]init];
SEL s1 = @selector(eat);
[p performSelector:s1];
SEL s2 = @selector(call:);
[p performSelector:s2 withObject:@"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