我有以下功能,它在Xcode 6 beta 2中运行良好
func connectPotentially(node: MazeNode)
{
if node.position != self.position && self.potentialPaths[node.position] == nil {
self.potentialPaths[node.position] = node
node.potentialPaths[self.position] = self
println("Potential path between \(self.position.level)x\(self.position.index) and \(node.position.level)x\(node.position.index)")
}
}
然而,在Xcode 6 beta 3中,我收到以下错误:
我不知道这是什么意思。有什么想法吗?也许是一个错误?
这是文件的完整转储:
import Foundation
struct MazeNodePosition : Hashable, Equatable {
var level: Int
var index: Int
var hashValue: Int {
get {
return level * 0xffff + index
}
}
}
@infix func ==(left: MazeNodePosition, right: MazeNodePosition) -> Bool
{
return left.level == right.level && left.index == right.index
}
class MazeNode {
let position: MazeNodePosition
var potentialPaths: Dictionary<MazeNodePosition, MazeNode> = [:]
var paths: Dictionary<MazeNodePosition, MazeNode> = [:]
var visited: Bool = false
init(position: MazeNodePosition)
{
self.position = position
}
func connectPotentially(node: MazeNode)
{
if node.position != self.position && self.potentialPaths[node.position] == nil {
self.potentialPaths[node.position] = node
node.potentialPaths[self.position] = self
println("Potential path between \(self.position.level)x\(self.position.index) and \(node.position.level)x\(node.position.index)")
}
}
func tryConnecting(node: MazeNode) -> Bool
{
if node.position != self.position && self.paths[node.position] == nil && !node.visited {
self.paths[node.position] = node
node.paths[self.position] = self
node.visited = true
self.visited = true
println("Path between \(self.position.level)x\(self.position.index) and \(node.position.level)x\(node.position.index)")
return true
}
return false
}
}
答案 0 :(得分:1)
简单修复if语句:
self.paths[node.position] == nil
应写成:
self.paths[node.position]