Setting up Structure SDK in Swift with XCode9 for using Structure Sensor

Structure Sensor is a convenient 3D Sensor used for 3D modelling, especially on your mobiles. This sensor comes along with an IOS SDK for developers to build up any application in a relaxing way.

Basically, all sample works provided is based on Objective-C while Swift is a more ease language to use. The original post is a bit outdated andthis tutorial will help you set up the environment in XCode9 and Swift4.


Steps:

  1. Get one SDK downloaded from https://structure.io/developers.

2. Create your own Swift project and create a new group to the project, name it as ‘Frameworks’.

3. From the downloaded SDK, find the Structure.framework files under /Frameworks then dragging it into the ‘Frameworks’ group in Xcode.

4. Click on the project in project navigator. Then choosing `Build Settings`.

  • Set `Other linker flags` to `-lc++`.
  • Set `Header Search Paths` to `$(PROJECT_DIR)/Structure.framework/Headers`.
  • Set `ENABLE_BITCODE` to `no`.

5. Go to `Build Phases`. Expand `Link Binary With Libraries`. Structure.framework should already by listed due to step 3. Then adding the following frameworks: `libz.tbd`, `Accelerate.framework`, `ImageIO.framework`, `ExternalAccessory.framework`.

6. Go to `Info.plist` from project navigator. Add a row for `Supported external accessory protocols`, then adding three items: `io.structure.control`, `io.structure.depth`, `io.structure.infrared`.

7. Create an arbitrary Objective-C file for auto-generating a bridging header file. Feel free tot delete the created Objective-C file.

Click ‘Create Bridging Header’

We will only keep the bridging header file. You can safely delete the obj-c file.

8. Adding to the bridging header:

#define HAS_LIBCXX 
#import "Structure/Structure.h"
#import "Structure/StructureSLAM.h"

9. Press Command + B to build the project to see if any error occurs while importing the Structure SDK. If everything goes correctly, you shall be able to use `STSensorControllerDelegate` on your controllers.

Go for the next episode: