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

Xcode はXXX-Bridging-Header.h、最初の Objective-C ファイルを追加するときに を作成するように求めます。このファイルを作成します。

クラスのインポートを「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"

これで、この (ハッキーな) ブリッジを使用して、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 に答える