Bridging the Gap to Objective-C

Swift allows you to bring in Objective-C code and use it directly in your Swift code. You can create classes, enums, and structs—and anything else you want. If something is not available in Swift that is available in Objective-C, you can easily make it available yourself by bridging. In this case, you want to add a low-level library called SIMD.h to your game. But before you can add it, you need to bridge it to Swift. In SIMDHelper.h, add the following content:

#import <Foundation/Foundation.h>#import <SceneKit/SceneKit.h>#import <simd/simd.h>@interface SIMDHelper : NSObject{}+ (SCNVector3) vector_maker:(float)followMeX :(float)followMeY   :(float)followMeT :(SCNVector3)cameraSCNVector3 ...

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.