SCNPhysicsWorld错误 [英] SCNPhysicsWorld Error
问题描述
我一直在搞乱swift并试图让Physicsworld工作。
I've been messing around with swift and trying to get a Physicsworld working.
这是我得到的错误
架构i386的未定义符号:
_ OBJC_CLASS _ $ _ SCNPhysicsWorld,引用自:
__TFC3sk218GameViewController11viewDidLoadfS0_FT_T_在GameViewController.o
ld:找不到架构i386的符号
clang:错误:链接器命令失败退出代码1(使用-v查看调用)
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.
推荐答案
Obj-c / Swift桥存在一个错误。
There is a bug here with the Obj-c / Swift bridge.
在等待解决方案时,您可以通过为自己创建一个临时桥来解决此问题:
While you wait for a solution, you can work around this by creating a temporary bridge for yourself:
添加以下类:
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应该提示你创建添加第一个objective-c文件时, XXX-Bridging-Header.h
。让它创建这个文件。
Xcode should prompt you to create a XXX-Bridging-Header.h
when you add the first objective-c file. Let it create this file.
将类的导入添加到'XXX-Bridging-header.h':
Add an import for the class to the '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的属性:
Now you can use this (hacky) bridge to set the properties from 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));
这篇关于SCNPhysicsWorld错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!