The Leap Motion Objective-C API is implemented as a wrapper around the Leap C++ API. The Objective-C wrapper allows you to program Leap-enabled applications in Objective-C (rather than Objective-C++ or C++).

To include the Leap API in an Objective-C project, add the following files from the Leap SDK:

  • include/LeapObjectiveC.h and include/LeapObjectiveC.mm
  • include/Leap.h and include/LeapMath.h
  • lib/libLeap.dylib

In addition, add a Copy Files Build Phase to the project and copy libLeap.dylib to the Executables destination.

Accessing Leap tracking data in your application

The LeapController class provides access to the Leap tracking data through LeapFrame objects. You can either poll the LeapController object when your application is ready to process a frame of data use one of the available event protocols to receive a message when a new frame is ready (as well as other events). The recommended mechanism for handling Leap events is to implement the LeapListener protocol. The LeapListener protocol uses NSNotifications and delivers messages on the main application thread. You can also use the LeapDelegate protocol and add a delegate to the controller object. However, the delegate callbacks are called on threads created by the Leap library rather than the main thread, so you must ensure that you only perform thread-safe operations in the delegate functions.