如何让一个类能被copy修饰

来源:互联网 发布:国密算法是否可解密 编辑:程序博客网 时间:2024/06/09 20:35

//

//  Person.h

//  tst

//

//  Created by zmx on 16/2/17.

//  Copyright © 2016 zmx. All rights reserved.

//


#import <Foundation/Foundation.h>


@interface Person :NSObject <NSCopying>


@property (nonatomic,copy) NSString *name;


@end


//

//  Person.m

//  tst

//

//  Created by zmx on 16/2/17.

//  Copyright © 2016 zmx. All rights reserved.

//


#import "Person.h"


@implementation Person


- (id)copyWithZone:(NSZone *)zone {

    Person *person = [PersonallocWithZone:zone];

    person.name = self.name;

    return person;

}


@end





0 0
原创粉丝点击