在Swift中使用GLKit中的GLKMath [英] Using GLKMath from GLKit in Swift
问题描述
var raw:GLKVector3 = GLKVector3Make(不相关的东西)
我得到以下错误:
使用模块GLKVector3作为类型。
我在GLKit的swift文件顶部有一个导入:
import GLKit
任何想法如何从GLKMath文件中获得用于我的程序的功能? p>
解决方案Swift在1.2版本中增加了union支持。即使使用
var
声明,导入的联合中的字段也是只读的,但可以根据需要传入和传出C函数。
Swift 1.2的发行说明意味着这些字段可能根本不可访问,但至少对于
GLKit
类型,它们仍可读:
Swift现在可以部分导入包含联合,位域,SIMD向量类型以及Swift中本机不支持的其他C语言功能的C聚合。不支持的字段将无法从Swift访问,但具有参数和这些类型的返回值的C和Objective-C API可以在Swift中使用。这包括Foundation
NSDecimal
类型和GLKit GLKVector
和GLKMatrix
类型等。
So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
I get the following error:
use of module GLKVector3 as type.
I have an import at the top of my swift file for GLKit:
import GLKit
Any ideas how I can get the functionality from the GLKMath files to use in my program?
解决方案Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with
var
, but can be passed to and from C functions as necessary.The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the
GLKit
types:Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation
NSDecimal
type and theGLKit GLKVector
andGLKMatrix
types, among others.
这篇关于在Swift中使用GLKit中的GLKMath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!