Sha256: 9392a422ea85e005fd921b44f8b7e885e01ce4bf523c9bc0f20abb24f47f811e

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 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
  
  def nsset
    NSSet.setWithArray self
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sugarcube-0.20.25 lib/sugarcube/nsarray.rb
sugarcube-0.20.24 lib/sugarcube/nsarray.rb
sugarcube-0.20.23 lib/sugarcube/nsarray.rb
sugarcube-0.20.22 lib/sugarcube/nsarray.rb
sugarcube-0.20.21 lib/sugarcube/nsarray.rb
sugarcube-0.20.20 lib/sugarcube/nsarray.rb
sugarcube-0.20.19 lib/sugarcube/nsarray.rb
sugarcube-0.20.18 lib/sugarcube/nsarray.rb
sugarcube-0.20.17 lib/sugarcube/nsarray.rb
sugarcube-0.20.16 lib/sugarcube/nsarray.rb
sugarcube-0.20.15 lib/sugarcube/nsarray.rb
sugarcube-0.20.13 lib/sugarcube/nsarray.rb
sugarcube-0.20.12 lib/sugarcube/nsarray.rb
sugarcube-0.20.11 lib/sugarcube/nsarray.rb
sugarcube-0.20.10 lib/sugarcube/nsarray.rb
sugarcube-0.20.9 lib/sugarcube/nsarray.rb
sugarcube-0.20.8 lib/sugarcube/nsarray.rb
sugarcube-0.20.7 lib/sugarcube/nsarray.rb
sugarcube-0.20.6 lib/sugarcube/nsarray.rb
sugarcube-0.20.5 lib/sugarcube/nsarray.rb