ios - 展开要打印的 SCNVector3/SCNVector4 值?

标签 ios swift scenekit

这应该是一个简单的问题

   import SceneKit
    import Accelerate

    var str:SCNVector3 = SCNVector3Make(1, 2, -8)
    println("vector \(str)" 

回答

vector C.SCNVector3

如何展开和显示像[ 1, 2, -8] 这样的向量?

最佳答案

Swift 2 更新:在 Swift 2 中,结构默认打印 具有所有属性:

let str = SCNVector3Make(1, 2, -8)
print("vector \(str)")
// Output:
// vector SCNVector3(x: 1.0, y: 2.0, z: -8.0)

您可以通过采用 CustomStringConvertible 自定义输出 协议(protocol):

extension SCNVector3 : CustomStringConvertible {
    public var description: String {
        return "[\(x), \(y), \(z)]"
    }
}

let str = SCNVector3Make(1, 2, -8)
print("vector \(str)")
// Output:
// vector [1.0, 2.0, -8.0]

上一个答案:

正如 Eric 已经解释过的,println() 检查对象是否符合 到 Printable 协议(protocol)。您可以为 SCNVector3 添加一致性 使用自定义扩展名:

extension SCNVector3 : Printable {
    public var description: String {
        return "[\(self.x), \(self.y), \(self.z)]"
    }
}

var str = SCNVector3Make(1, 2, -8)
println("vector \(str)")
// Output:
// vector [1.0, 2.0, -8.0]

关于ios - 展开要打印的 SCNVector3/SCNVector4 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28885254/

相关文章:

iphone - 从不存在的 View 中删除 subview

php - 使用 Swift 连接到 PHP 服务器

ios - 如何在 iOS 中更改 Chirp 的 SDK 状态?

SceneKit SCNPhysicsVehicle 问题

ios - 如何使用 SceneKit iOS 添加背面图像作为纹理

ios - 这次崩溃的可能原因是什么?

ios - 如何更新在 UITableViewCell 中添加的 View ?

ios - Swift - 无法在 UITextField 中从用户自定义光标位置

ios - @testable 导入出现奇怪的编译错误

scenekit - SCNNode.flattenedClone() 不会减少绘制调用