Although working with RubyMotion does not require one to learn Objective-C, or even C for that matter, sometimes when you want to use the iOS API, knowledge of its Ruby equivalent is beneficial. Objective-C is a superset of the C language. Objective-C methods can therefore accept and return C-language types.
C language—and indirectly Objective-C—has a set of basic data types that are used in the iOS SDK APIs. In order to accept or return these data types, we need some equivalent data types for Ruby.
For example, let's create a function named foo
that accepts a C integer type as a parameter and returns the some_number
integer:
int foo(int some_number) { return some_number; }
So, if we want to call the preceding function from Ruby, we will require some equivalent Ruby type. Basic C types cannot be created from Ruby directly, but are automatically converted from and to equivalent Ruby types. You don't have to worry, RubyMotion will take care of this for...