限制对象类型:
让类遵循某个协议,对使用的对象进行限制
//
// LMC.h
// OCStudy
//
// Created by LiuMingchuan on 15/9/27.
// Copyright © 2015年 LMC. All rights reserved.
//
#import "Person.h"
#import "MyProtocol.h"
@interface LMC : Person <MyProtocol>
@property (nonatomic,assign)int age;
@end
LMC遵从MyProtocol协议
<pre name="code" class="objc"> NSObject<MyProtocol> *object0 = [[NSObject alloc]init];
NSLog(@"%@",object0);
NSObject<MyProtocol> *object1 = [[LMC alloc]init];
NSLog(@"%@",object1);
id<MyProtocol> object3 = [[LMC alloc]init];//id相当于 NSObject*,所以object3不加*
N