5

I've been messing around with swift and trying to get a Physicsworld working.

This is the error I get "Undefined symbols for architecture i386: "_OBJC_CLASS_$_SCNPhysicsWorld", referenced from: __TFC3sk218GameViewController11viewDidLoadfS0_FT_T_ in GameViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) "

I assume it has to do with linking or importing a library that I'm not, but I have added everything that I could find that I thought might fix it (found in other posts on game kit) Does anyone know what this might be? Thanks.

4

1 回答 1

8

Obj-c / Swift 桥有一个错误。

在等待解决方案时,您可以通过为自己创建一个临时桥来解决此问题:

添加以下类:

PhysWorldBridge.h

#import <Foundation/Foundation.h>
#import <SceneKit/SceneKit.h>//

@interface PhysWorldBridge : NSObject

- (void) physicsWorldSpeed:(SCNScene *) scene withSpeed:(float) speed;
- (void) physicsGravity:(SCNScene *) scene withGravity:(SCNVector3) gravity;

@end

PhysWorldBridge.m

#import "PhysWorldBridge.h"

@implementation PhysWorldBridge

- (id) init
{
    if (self = [super init])
    {        
    }
    return self;
}

- (void) physicsWorldSpeed:(SCNScene *) scene withSpeed:(float) speed
{
    scene.physicsWorld.speed = speed;
}

- (void) physicsGravity:(SCNScene *) scene withGravity:(SCNVector3) gravity
{
    scene.physicsWorld.gravity = gravity;
}

@end

XXX-Bridging-Header.h当您添加第一个objective-c 文件时,Xcode 应该会提示您创建一个。让它创建这个文件。

将类的导入添加到“XXX-Bridging-header.h”:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "PhysWorldBridge.h"

现在你可以使用这个(hacky)桥从 Swift 中设置属性:

//scene.physicsWorld.speed = 2.0
// CAN'T USE ABOVE OR LINKER ERROR


let bridge = PhysWorldBridge();
bridge.physicsWorldSpeed(scene, withSpeed: 2.0);
//This call bridges properly

//So would the gravity one:
bridge.physicsGravity(scene, withGravity: SCNVector3Make(0, -90.81, 0));
于 2014-06-11T13:29:49.280 回答