0
此程序无法通过Xcode进行编译,只能在IOS应用程序“Playgrounds”中运行。无法使用类型为'(Number)'的参数列表调用类型为'Int'的初始值设定项。
在IOS应用 “游乐场” - > “学习代码3”(SWIFT 3.1) - > “音乐宇宙” 我有下面的代码:
// A touch event for when your finger is moving across the scene.
// Declaration
struct Touch
// The position of this touch on the scene.
// Declaration
var position: Point
// The x coordinate for the point.
// Declaration for touch.position.x
var x: Double
以上只是为了说明。
let touch: Touch
let numberOfNotes = 16
let normalizedXPosition = (touch.position.x + 500)/1000
let note = normalizedXPosition * (numberOfNotes - 1)
let index = Int(note)
最后一句显示错误: 不能调用初始化类型“诠释”类型的参数列表“(编号)”。 我怎么能转换note
到Int
类型?
什么类型都有'touch.position.x'? - 一个显示问题的自包含*示例将有所帮助。 –
对于第一次看,我认为'touch.position.x'类型为CGFloat的,但现在看来,这是不是因为你应该得到'让注= normalizedXPosition *(numberOfNotes - 1)编译时错误',抱怨关于Int和CGFloat之间的乘积。 –
我已添加touch.position.x的注释,touch.position.x类型为'Double' – linjie