Module: BubbleWrap::Constants

Defined in:
motion/util/constants.rb

Class Method Summary collapse

Class Method Details

.get(base, *values) ⇒ Integer

Examples get(“UIReturnKey”, :done) => UIReturnKeyDone == 9 get(“UIReturnKey”, “done”) => UIReturnKeyDone == 9 get(“UIReturnKey”, 9) => 9 get(“UIImagePickerControllerSourceType”, [“photo_library”, “camera”, “saved_photos_album”]) => 3 get(“UIActivityType”, [:air_drop, :print]) => [“com.apple.UIKit.activity.AirDrop”, “com.apple.UIKit.activity.Print”]


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'motion/util/constants.rb', line 26

def get(base, *values)
  value = values.size == 1 ? values.first : values.flatten
  case value
  when Numeric
    value.to_i
  when NSArray
    unless get(base, value.first).is_a? Fixnum
      value.map { |v| get(base, v) }
    else
      value.reduce { |i, j|
        get(base, i) | get(base, j)
      }
    end
  else
    value = value.to_s.camelize
    Kernel.const_get("#{base}#{value}")
  end
end

.register(*ui_constants) ⇒ Object

Looks like RubyMotion only adds UIKit constants at compile time. If you don't use these directly in your code, they don't get added to Kernel and Constants.get crashes. Examples Constants.register UIReturnKeyDone, UIReturnKeyNext


12
13
14
# File 'motion/util/constants.rb', line 12

def register(*ui_constants)
  # do nothing, just get the constants in the code
end