美文网首页
Working with Instances

Working with Instances

作者: 事件_666 | 来源:发表于2017-05-05 21:19 被阅读0次

    1 arc 下不能用 非arc下确实强大
    id object_copy(id obj, size_t size);

    Singleton *sigle = [Singleton shareInstance];
    sigle.name = @"XXXX";
    Singleton *sig2 =   object_copy(sigle, sizeof([Singleton class]));
    sig2.name = @"AAAAA";
    NSLog(@"==:%@",sig2.name);
    NSLog(@"==:%@",sig.name);
    

    2 --------------------------------------------------
    arc 下不能使用
    Ivar object_setInstanceVariable(id obj, const char *name, void *value);
    Ivar object_getInstanceVariable(id obj, const char *name, void **outValue);
    3------------------------------------------------
    //注意这里没有使用getset方法所以getset方法里的属性设置也是无效的
    id object_getIvar(id obj, Ivar ivar);
    int obj = object_getIvar(aClass, ivar);
    NSLog(@"obj=:%d",obj);
    void object_setIvar(id obj, Ivar ivar, id value);

    4-------------------------------------------------
    const char * object_getClassName(id obj);
    Class object_setClass(id obj, Class cls);//KVO 用到了

    相关文章

      网友评论

          本文标题:Working with Instances

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