Protocol versus Category

后端 未结 7 1577
忘了有多久
忘了有多久 2020-12-12 14:09

Can anyone explain the differences between Protocols and Categories in Objective-C? When do you use one over the other?

7条回答
  •  悲哀的现实
    2020-12-12 14:27

    To my understanding Protocols are a bit like Java's Interfaces. Protocols declare methods , but the implementation is up to each class. Categories seems to be something like Ruby's mixins. With Categories you can add methods to existing classes. Even built-in classes.

提交回复
热议问题