This article discusses how to set up and compile Objective-C projects with Xcode. The Leap Motion Objective-C API is provided as a Objective-C++ wrapper that allows you to access the C++ API using pure Objective-C code. Every Objective-C project must include the following files:
To set up a Leap Motion project in Xcode:
Open or create an Xcode project.
Add the Leap Motion SDK include files and API library:
Configure the project to bundle libLeap.dylib with the application:
- Go to the target Build Phases page.
- Add a build phase using the Menu command: Editor>Add Build Phase>Add Copy Files Build Phase.
- Open the new phase.
- Set destination to Executables.
- Add libLeap.dylib to the list of files.
The Leap Motion wrapper files, LeapObjectiveC.mm and LeapObjectiveC.h, require ARC. To use this wrapper in a non-ARC project, you have two options: You can switch the project as a whole to use ARC and then add the -fno-objc-arc flag to those components that cannot be easily converted. Alternately, you can compile the Leap Motion wrapper files with the -fobjc-arc flag.
If you wish to load the libLeap dynamic library from a different location than your application executable, you can use the OS X install_name_tool to change the loader path. For example, to load the library from the Resources folder of a standard Mac application package instead of the MacOS folder, you could run the following command:
On Mac OS X:
install_name_tool -change @loader_path/libLeap.dylib @executable_path/../Resources/libLeap.dylib Sample
(where Sample is your application binary).