Skip to content

Instantly share code, notes, and snippets.

@cicloid
Created November 15, 2012 19:12
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/4080564 to your computer and use it in GitHub Desktop.
Save cicloid/4080564 to your computer and use it in GitHub Desktop.
# Makes any NSObject conform to the NSCoding protocol
module Serializable
def initWithCoder(coder)
self.init
methods.grep(/\w=:$/).each do |method|
key = method.to_s.sub('=:', '')
self.send(method, coder.decodeObjectForKey(key))
end
self
end
def encodeWithCoder(coder)
methods.grep(/\w=:$/).each do |method|
key = method.to_s.sub('=:', '')
coder.encodeObject(self.send(key), forKey: key)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment