NSCopying

///< .h
@interface ChatManager : NSObject <NSCopying>
@property (nonatomic) NSUInteger index;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, strong) NSMutableString *muStr;
@end


///< .m
@implementation ChatManager
- (id)copyWithZone:(NSZone *)zone {
    ChatManager *mgr = [self.class new];
    mgr.name = _name;
    mgr.index = _index;
    mgr.muStr = _muStr;
    mgr.titles = _titles;
    mgr.userInfo = _userInfo;
    return mgr;
}
@end

 关于深拷贝和浅拷贝,请参考:传送门

posted @ 2016-09-30 15:05  Kingdev  阅读(114)  评论(0编辑  收藏  举报