Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有一个函数,在调用时需要返回一个CGFloat值。但是,Xcode 以错误消息响应:“CGFloat is not convertible to ()”。我浏览了网络,但似乎没有一个转换对我有用。
CGFloat
这是我的功能
func update() { point2.y += 1.39 return point2.y //<<<LINE OF ERROR<<<// }
您的函数未指定返回类型。
在 Swift 中,您使用箭头 ( ->) 表示法来表示这一点。
->
尝试
func update() -> CGFloat { point2.y += 1.39 return point2.y }
“CGFloat is not convertible to ()”意味着你的方法返回 CGFloat 类型的东西,而返回类型是 Void(或())。
()