Exercise 3: Initiate the binding process on an existing Xcode framework project (IOS451)
The primary goal of this lab is to bind an existing Xcode Framework using Objective Sharpie.
If you haven't already, you will need to download Objective Sharpie. Additionally, you will need to complete this exercise on a Mac running macOS 10.10 or newer for compatiblity with Objective Sharpie.
Objective Sharpie has a minimum requirement of macOS 10.10 or newer.
Clone target library
To start, you are going to clone the Pop animation library again.
- Create a folder for you exercise content.
- Open Terminal and navigate to your exercise folder.
- Type the following command to clone the Pop library from GitHub.
git clone https://github.com/facebook/pop.git
Build project with Xcode
Now, we'll build the Pop project using Xcode.
- Navigate your command-prompt to the newly Git-created pop folder.
- Run the following command.
xcodebuild -sdk iphoneos11.4 -arch arm64
You may need to adjust the-sdk
parameter to match an installed SDK version on your PC. If you are unsure what SDKs you have installed, you can list available Xcode SDKs withsharpie xcode -sdks
.
Process project into an API definition
Now, we can run an Objective Sharpie command to process the library into the API definition files.
- Run the following command in the pop folder. It is broken into multiple lines for easier legibility; make sure to copy the whole command.
sharpie bind -output XamarinFacebookPop -namespace FacebookPOP \
-sdk iphoneos11.4 -scope build/Release-iphoneos/include/pop/ \
build/Release-iphoneos/include/pop/POP.h
There are a few aspects that needs to be specified for the binding:
- There are a few aspects that needs to be specified for the binding:
- The output path used for the generated API files, for example
XamarinFacebookPop
. - The namespace for the binding, for example
FacebookPop
. - The iOS SDK version used to create the binding, for example
iphoneos11.4
- The scope used to reference header files, for example
build/Release-iphoneos/include/pop/
- The umbrella header file to base the binding on. The header files for this project, POP.h is located in the build/Release-iphoneos/include/pop/ folder.
You may need to adjust the-sdk
parameter to match an installed SDK version on your PC. If you are unsure what SDKs you have installed, you can list available Xcode SDKs withsharpie xcode -sdks
.
You will see an error in the Objective Sharpie output like this, suggesting an include from POP.h wasn't found. The #import statements are defined using angle-brackets which define global includes. Using global includes requires relative or absolute paths passed to the compiler. Objective Sharpie however will not find the files, as specified, since the path is interpreted absolutely. Change the #import statement to make use quotation marks.
'Parsing 1 header files...
/.../pop/build/Release-iphoneos/include/pop/POP.h:13:9: fatal error: 'pop/POPDefines.h' file not found
#import <pop/POPDefines.h>
^~~~~~~~~~~~~~~~~~
Binding...
1 error generated.
Error while processing /.../pop/build/Release-iphoneos/include/pop/POP.h.'
- Open the POP.h file in the pop/build/Release-iphoneos/include/pop/ folder and update all the #import statements.
For example, for this import statement:
#import <pop/POPDefines.h>
You would update it to look like this (using quotation marks and omitting the pop/
sub-folder.):
#import "POPDefines.h"
Do not change any of the external libraries used. For example, all imports which do not include the prefixpop
, such as#import <Foundation/NSException.h>
.
- With these updates in place, re-run the
sharpie
command.
Next, you will see that each of the referenced files from POP.h also reference other imports that need to be updated.
For example, this is the error reported for the POPAnimatableProperty.h file.
'Parsing 1 header files...
In file included from /.../pop/build/Release-iphoneos/include/pop/POP.h:15:
/.../pop/build/Release-iphoneos/include/pop/POPAnimatableProperty.h:14:9: fatal error: 'pop/POPDefines.h' file not found
#import <pop/POPDefines.h>
^~~~~~~~~~~~~~~~~~
Binding...
[write] ApiDefinitions.cs
[write] StructsAndEnums.cs'
...
- Update the
#import <pop/{file}.h>
references in the remaining Pop header files, switching the statements to use quotation marks and omit thepop/
sub-folder.
If you miss any files, Objective Sharpie will report a similar error for any files you have remaning to update.
- With these manual edits in place, run the
sharpie
command again.
Inspect the current folder to make sure Objective Sharpie created a folder called XamarinFacebookPop containing two files.
- ApiDefinitions.cs
- StructsAndEnums.cs
Exercise summary
In this exercise you saw how to initiate the binding process on an existing Xcode Framework project using Objective Sharpie.