Sha256: 638d97a1114d59c3c588022f697623a77fc38a6009bc91e5b43418d17f31c38f

Contents?: true

Size: 872 Bytes

Versions: 4

Compression:

Stored size: 872 Bytes

Contents

class NSUserDefaults

  class << self
    # Retrieves the object for the passed key
    def [](key)
      self.standardUserDefaults.objectForKey(key.to_s)
    end

    # Sets the value for a given key and save it right away.
    def []=(key, val)
      self.standardUserDefaults.setObject(val.to_nsuserdefaults, forKey: key.to_s)
      self.standardUserDefaults.synchronize
    end

    def remove(key)
      self.standardUserDefaults.removeObjectForKey(key)
      self.standardUserDefaults.synchronize
    end
  end

end


class Object
  def to_nsuserdefaults
    self
  end
end


class NilClass
  def to_nsuserdefaults
    false
  end
end


class NSArray
  def to_nsuserdefaults
    self.map { |val| val.to_nsuserdefaults }
  end
end


class NSDictionary
  def to_nsuserdefaults
    self.each_with_object({}) { |(key, val), h| h[key] = val.to_nsuserdefaults }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sugarcube-0.13.3 lib/sugarcube/nsuserdefaults.rb
sugarcube-0.13.2 lib/sugarcube/nsuserdefaults.rb
sugarcube-0.13 lib/sugarcube/nsuserdefaults.rb
sugarcube-0.12 lib/sugarcube/nsuserdefaults.rb