O'Reilly logo

RubyMotion iOS Development Essentials by Abhishek Nalwaya, Akshat Paul

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interfacing with C and Objective-C

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.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required