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
关于深拷贝和浅拷贝,请参考:传送门