这应该是一个简单的问题
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/