Class: NSArray

Inherits:
Object show all
Defined in:
lib/sugarcube/nsarray.rb,
lib/sugarcube/nsuserdefaults.rb

Instance Method Summary collapse

Instance Method Details

#nsindexpathNSIndexPath

Creates an NSIndexPath object using the items in self as the indices

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sugarcube/nsarray.rb', line 15

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

#nsindexsetNSIndexSet

Creates an NSIndexSet object using the items in self as the indices

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sugarcube/nsarray.rb', line 33

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

#to_nsuserdefaultsObject



43
44
45
# File 'lib/sugarcube/nsuserdefaults.rb', line 43

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

#to_pointer(type) ⇒ Pointer

Returns A pointer to the array, of the specified type.

Parameters:

Returns:

  • (Pointer)

    A pointer to the array, of the specified type



5
6
7
8
9
10
11
# File 'lib/sugarcube/nsarray.rb', line 5

def to_pointer(type)
  ret = Pointer.new(type, self.length)
  self.each_index do |i|
    ret[i] = self[i]
  end
  ret
end

#uicolor(alpha = 1.0) ⇒ Object

[160, 210, 242].uicolor => 0xA0D2F2.uicolor



46
47
48
49
50
51
# File 'lib/sugarcube/nsarray.rb', line 46

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