What is the type of SCNVector3 components? CGFloat or Float?

China☆狼群 提交于 2019-12-01 07:48:57

问题


The apple documentation gives the declaration of SCNVector3 :

typedef struct SCNVector3 { CGFloat x, y , z; } SCNVector3;

Or when trying to write an overload function :

func * (left: SCNVector3, right: CGFloat) -> SCNVector3 {
    return SCNVector3Make(left.x * right, left.y * right, left.z * right)
}

I get the "cannot invoke '' with an argument list of type" error. Aren't left.x, left.y and left.z supposed to be CGfloat ?

How and when is it decided if CGFloat will be a double or a float?


回答1:


In the iOS 8.1 SDK headers, the SCNVectorX types are based on Float, as can be seen by command-clicking on SCNVector3:

struct SCNVector3 {
    var x: Float
    var y: Float
    var z: Float
}

func SCNVector3Make(x: Float, y: Float, z: Float) -> SCNVector3

This is different from the OS X 10.10 SDK where CGFloat is used. So the documentation seems to be wrong. The following compiles in an iOS project:

func * (left: SCNVector3, right: Float) -> SCNVector3 {
    return SCNVector3Make(left.x * right, left.y * right, left.z * right)
}


来源:https://stackoverflow.com/questions/27877080/what-is-the-type-of-scnvector3-components-cgfloat-or-float

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!