Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Objective-C support Mixin like Ruby?

In Ruby, there's Modules and you can extend a class by "mixing-in" the module.

module MyModule   def printone     print "one"    end end  class MyClass   include MyModule end  theOne = MyClass.new theOne.printone  >> one 

In Objective-C, I find that I have a set of common methods that I want a number of Class to "inherit". What other ways can I achieve this without creating a common class and deriving all from that common class?

like image 358
hacksignal Avatar asked Mar 21 '10 07:03

hacksignal


1 Answers

Shameless plug: ObjectiveMixin

It takes advantage of Objective-C runtime's capability of adding methods to a class in runtime (as opposed to categories, which are compile-time only). Check it out, it works pretty good and in a similar fashion to Ruby's mixins.

like image 127
Vladimir Mitrovic Avatar answered Sep 28 '22 06:09

Vladimir Mitrovic