我正在为Swift编写本教程:https : //www.raywenderlich.com/125311/make-game-like-candy-crush-spritekit-swift-part-1并遇到以下代码:
func == (lhs: Cookie, rhs: Cookie) -> Bool {
return lhs.column == rhs.column && lhs.row == rhs.row
}
我正是这样写的,但是Xcode给出了我这些错误:
Consecutive declarations on a line must be separated by ';'
Expected declaration operators are only allowed at global scope
我从苹果的文档中找到了以下代码:https : //developer.apple.com/documentation/swift/equatable
这与我写的非常相似。怎么了?对我来说,这似乎是个错误。我正在使用Xcode 6 Beta 2
编辑:
这是我的整个Cookie课:
class Cookie: Printable, Hashable {
var column: Int
var row: Int
let cookieType: CookieType
let sprite: SKSpriteNode?
init(column: Int, row: Int, cookieType: CookieType) {
self.column = column
self.row = row
self.cookieType = cookieType
}
var description: String {
return "type:\(cookieType) square:(\(column),\(row))"
}
var hashValue: Int {
return row * 10 + column
}
func ==(lhs: Cookie, rhs: Cookie) -> Bool {
return lhs.column == rhs.column && lhs.row == rhs.row
}
}