Class method and instance method with the same name in Objective-C

十年热恋 提交于 2019-12-05 04:47:43

This is what code comments are for :)

There's no problem in Objective C with a class method and instance method having the same name.

I would suggest either:

  • amend your notification method name spec to handle this (and then handle the class notification with a different appropriately named method), or

  • add appropriate comment to explain what's happening for benefit of future potentially confused developers

The language itself and the runtime will see no ambiguity in what you're doing. So you're safe on that front.

In terms of confusing future maintainers I guess you needn't be too concerned with silly autocomplete mistakes because it's not a method you intend to make manual calls to.

That said, I'd be tempted to move the class stuff into an artificial category. That'll not only give separation on the page but make it explicit that the class intends to respond as a separate tranche of functionality from the instance responses.

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