# Makes any NSObject conform to the NSCoding protocol # Authors: # @rod_wilhelmy # @cicloid module Serializable def attr_accessor_setters methods.grep(/\w=:$/) end def initWithCoder(coder) self.init attr_accessor_setters.each do |method| key = method.to_s.sub('=:', '') self.send(method, coder.decodeObjectForKey(key)) end self end def encodeWithCoder(coder) attr_accessor_setters.each do |method| key = method.to_s.sub('=:', '') coder.encodeObject(self.send(key), forKey:key) end end end