问题描述
Apple文档给出了SCNVector3的声明:
The apple documentation gives the declaration of 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)
}
我得到无法调用''的参数列表类型为错误。是不是left.x,left.y和left.z应该是CGfloat?
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 ?
如果CGFloat是双重还是浮动,它是如何以及何时决定的?
How and when is it decided if CGFloat will be a double or a float?
推荐答案
在iOS 8.1 SDK标题中, SCNVectorX
类型基于在 Float
上,可以看到
通过命令点击 SCNVector3
:
In the iOS 8.1 SDK headers, the SCNVectorX
types are based on Float
, as can be seenby command-clicking on SCNVector3
:
struct SCNVector3 {
var x: Float
var y: Float
var z: Float
}
func SCNVector3Make(x: Float, y: Float, z: Float) -> SCNVector3
这与OS X 10.10 SDK不同,其中 CGFloat $使用c $ c>。所以文件
似乎是错误的。以下在iOS项目中编译:
This is different from the OS X 10.10 SDK where CGFloat
is used. So the documentationseems 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)
}
这篇关于SCNVector3组件的类型是什么? CGFloat还是Float?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!