iOS微知识点iOS DeveloperiOS接下来要研究的知识点

2018-4周-iOS工作杂技

2018-01-30  本文已影响16人  Corbin___

2018-4周

一、objc_getAssociatedObjectobjc_setAssociatedObject

主要是创建分类的时候用到,但是要注意的是,如果分类创建的属性是NSSArray...之类的,需要创建对象的,那么分类这个属性的get方法应该这样写

- (NSMutableArray *)array
{
    NSMutableArray *array = objc_getAssociatedObject(self, @"array");
    if (!array) {
        array = [[NSMutableArray alloc] init];
        self.array = array;
    }
    
    return array;
}

- (void)setArray:(NSMutableArray *)array
{
    objc_setAssociatedObject(self, @"array", array, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

二、mutableCopy和copy

mutableCopy:浅复制,指针复制
copy:深复制,内存复制
总结:

三、NSDecimalNumber

NSDecimalNumber is the subclass of NSNumber.
It is mainly used to solve the lack of precision.

四、代理要继承<NSObject>协议

调用代理的可选方法,经常要用到respondsToSelector,这个是<NSObject>协议里面的

if ([self.delegate respondsToSelector:@selector(ViewControllerBsendValue:)])
    {
        //如果协议响应了ViewControllerBsendValue:方法
        //通知代理执行协议的方法
        [_delegate ViewControllerBsendValue:_textField.text];
    }

五、static、extern、const

int * const p = NULL;
int a = 20;
*p = &a; // 编译器报错

六、clipsToBounds

具体的说,就是当它取值为 YES 时,剪裁超出父视图范围的子视图部分;当它取值为 NO 时,不剪裁子视图。
默认值为 NO,但是在 UIScrollView 中,它的默认值是 YES,也就是说默认裁剪的。

七、CGRectGetMinX、CGRectGetMaxX、CGRectGetMinY、CGRectGetMaxY

八、故事版的属性不走get、set方法

上一篇 下一篇

猜你喜欢

热点阅读