sizeOf() with iOS objects - ParkinT/RubyMotion_Life GitHub Wiki

Matthew Nguyen was stuck when converting Obj-C code using sizeof() into RubyMotion. How should I translate: sizeof(CTTextAlignment) ?

Here is a little method to get around the problem

def sizeof(type)
  size_ptr = Pointer.new(:uint)
  align_ptr = Pointer.new(:uint)
  NSGetSizeAndAlignment(type, size_ptr, align_ptr)
  size_ptr[0]
end

sizeof(CTParagraphStyleSetting.type) # => 12
sizeof(CGRect.type) # => 16
sizeof(:float) # => 4

The details are in this thread on the RubyMotion Google Groups