Sha256: 27f31a85f2720b3e0d06c3aff89fa9a17c27366c5c9549f29a8567b80b78405b

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# Hash-like access for NSCoder.  Converts the `key` argument to a String,
# because Symbols can mess things up.
class NSCoder

  def [] key
    self.decodeObjectForKey(key.to_s)
  end

  def []= key, value
    self.encodeObject(value, forKey: key.to_s)
  end

  def key?(key)
    self.containsValueForKey(key.to_s)
  end

  def bool(key)
    self.decodeBoolForKey(key.to_s)
  end

  def double(key)
    self.decodeDoubleForKey(key.to_s)
  end

  def float(key)
    self.decodeFloatForKey(key.to_s)
  end

  def int(key)
    self.decodeIntegerForKey(key.to_s)
  end

  def set(key, toBool: value)
    self.encodeBool(value, forKey: key.to_s)
    self
  end

  def set(key, toDouble: value)
    self.encodeDouble(value, forKey: key.to_s)
    self
  end

  def set(key, toFloat: value)
    self.encodeFloat(value, forKey: key.to_s)
    self
  end

  def set(key, toInt: value)
    self.encodeInteger(value, forKey: key.to_s)
    self
  end

end


class NSCoder

  def self.archive(root)
    NSKeyedArchiver.archivedDataWithRootObject(root)
  end

  def self.archive(root, to_file: file)
    NSKeyedArchiver.archivedRootObject(root, toFile: file)
  end

  def self.unarchive(data_or_file)
    if data_or_file.is_a?(NSData)
      NSKeyedUnarchiver.unarchiveObjectWithData(data_or_file)
    else
      NSKeyedUnarchiver.unarchiveObjectWithFile(data_or_file)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/cocoa/sugarcube-nscoder/nscoder.rb
sugarcube-3.5.0 lib/cocoa/sugarcube-nscoder/nscoder.rb
sugarcube-3.4.2 lib/cocoa/sugarcube-nscoder/nscoder.rb
sugarcube-3.4.1 lib/cocoa/sugarcube-nscoder/nscoder.rb
sugarcube-3.4.0 lib/cocoa/sugarcube-nscoder/nscoder.rb
sugarcube-3.3.7 lib/cocoa/sugarcube-nscoder/nscoder.rb