美文网首页
利用Runtime重写copyWithZone

利用Runtime重写copyWithZone

作者: huisedediao | 来源:发表于2018-03-05 15:22 被阅读0次
    - (id)copyWithZone:(NSZone *)zone
    {
        id copyObject = [[[self class] allocWithZone:zone] init];
        
        unsigned int count = 0;
        Ivar *ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++)
        {
            NSString *key = [[NSString stringWithUTF8String:ivar_getName(ivars[i])] substringFromIndex:1];
            [copyObject setValue:[self valueForKey:key] forKey:key];
        }
        return copyObject;
    }
    

    相关文章

      网友评论

          本文标题:利用Runtime重写copyWithZone

          本文链接:https://www.haomeiwen.com/subject/jbshfftx.html