objective-c - iOS开发中,工具类和分类的各自优缺点
大家讲道理
大家讲道理 2017-04-17 17:57:25
0
1
317

项目里经常会使用到工具类和分类,同一个功能两种方法都可以使用。
比如在
工具类(UIViewUtil)

+(void)setRadiusInView:(UIView *)view{
    view.cornerRadius = 1;
}

分类:UIView+Radius

-(void)setRadius{
    self.layer.cornerRadius = 1;
}

随手写的,这两个是常用的抽取复用代码的方式,各有什么优缺点,常用的场景,麻烦告知下。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
大家讲道理

It is definitely more convenient to use Category. The disadvantage is that you should pay attention to the extended method names so that they do not conflict. It is best to add a prefix. Also, if you use KVO or Notification, you must write the corresponding logout method in the dealloc method of the class that uses the extension method. This is not as convenient as Util. Util can directly write the logout in Util's dealloc method.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!