Two Categories on the same Class with the same method name

二次信任 提交于 2019-12-03 03:07:49

Name collision is indeed something that can happen in Objective-C runtime... Apple advises the use of 'prefix' on methods names.

The expected behaviour : only the last category/method loaded by the runtime will be effective. Which one is it ? Bad question !

My advice : rename !

bourou01

Rename doesn't seem to be the best way to resolve the problem,

just use :

[cell.imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

}];

from SDWebImage which doesn't exist in AFNetworking

For anyone looking to use both SDWebImage and AFNetworking as-is, here's my caveman solution to discourage use of the colliding methods:

https://gist.github.com/sibljon/5957892

It's obviously not future proof, and is prone to breaking if the implementation of these methods changes in AFNetworking or SDWebImage. It's far from an ideal solution. In other words, at your own risk!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!