Skip to content

Instantly share code, notes, and snippets.

@cicloid
Created November 15, 2012 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cicloid/4076001 to your computer and use it in GitHub Desktop.
Save cicloid/4076001 to your computer and use it in GitHub Desktop.
def initWithCoder(decoder)
self.init
da_methods = self.class.instance_methods.find_all do |method|
method != :== &&
method != :! &&
self.class.instance_methods.include?(:"#{method}=")
end
da_methods.each do |attr|
if decoder.containsValueForKey(attr.to_s)
value = coder.decodeObjectForKey(attr.to_s)
self.send("#{attr}=", value)
else
self.send("#{attr}=", nil)
end
end
self
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment