Sha256: 63a401ae0b7c43a212f030d1e99ce94f582e85a41cd9aa19e9ca3e397131d51e

Contents?: true

Size: 1.31 KB

Versions: 32

Compression:

Stored size: 1.31 KB

Contents

class NSArray

  # @param type [Symbol] type A pointer type from the list at {http://www.rubymotion.com/developer-center/guides/runtime/ RubyMotion Pointers Reference#_pointers}
  # @return [Pointer] A pointer to the array, of the specified type
  def to_pointer(type)
    ret = Pointer.new(type, self.length)
    self.each_index do |i|
      ret[i] = self[i]
    end
    ret
  end

  # Creates an NSIndexPath object using the items in `self` as the indices
  # @return [NSIndexPath]
  def nsindexpath
    if self.length == 0
      raise "An index path must have at least one index"
    end

    path = nil
    self.each do |val|
      if path
        path = path.indexPathByAddingIndex(val)
      else
        path = NSIndexPath.indexPathWithIndex(val)
      end
    end
    return path
  end

  # Creates an NSIndexSet object using the items in `self` as the indices
  # @return [NSIndexSet]
  def nsindexset
    if self.length == 0
      raise "An index set must have at least one index"
    end

    set = NSMutableIndexSet.indexSet
    self.each do |val|
      set.addIndex val
    end
    set
  end

  # [160, 210, 242].uicolor => 0xA0D2F2.uicolor
  def uicolor(alpha=1.0)
    red = self[0] / 255.0
    green = self[1] / 255.0
    blue = self[2] / 255.0
    UIColor.colorWithRed(red, green:green, blue:blue, alpha:alpha.to_f)
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
sugarcube-0.20.1 lib/sugarcube/nsarray.rb
sugarcube-0.20.0 lib/sugarcube/nsarray.rb
sugarcube-0.19.5 lib/sugarcube/nsarray.rb
sugarcube-0.19.4 lib/sugarcube/nsarray.rb
sugarcube-0.19.2 lib/sugarcube/nsarray.rb
sugarcube-0.19.0 lib/sugarcube/nsarray.rb
sugarcube-0.18.21 lib/sugarcube/nsarray.rb
sugarcube-0.18.20 lib/sugarcube/nsarray.rb
sugarcube-0.18.19 lib/sugarcube/nsarray.rb
sugarcube-0.18.18 lib/sugarcube/nsarray.rb
sugarcube-0.18.17 lib/sugarcube/nsarray.rb
sugarcube-0.18.16 lib/sugarcube/nsarray.rb
sugarcube-0.18.12 lib/sugarcube/nsarray.rb
sugarcube-0.18.11 lib/sugarcube/nsarray.rb
sugarcube-0.18.10 lib/sugarcube/nsarray.rb
sugarcube-0.18.9 lib/sugarcube/nsarray.rb
sugarcube-0.18.8 lib/sugarcube/nsarray.rb
sugarcube-0.18.7 lib/sugarcube/nsarray.rb
sugarcube-0.18.6 lib/sugarcube/nsarray.rb
sugarcube-0.18.5 lib/sugarcube/nsarray.rb