Hello Swift experts
I have a question that I know you know the answer to. I am writing some classes to build and handle a binary tree node. I think I have completed the task but am kinda unhappy with an error I got and I dont know why it appears. Please check the following sample of code out that reproduces the error, you can use a playground in XCode. I extracted this code from my class and simplified it to reproduce the failuere, so it doesn't follow any logic:
class BinaryTreeNode {
var data = 0
var left: BinaryTreeNode? = nil
var right: BinaryTreeNode? = nil
init(value: Int) {
self.data = value
}
func getLeftChild() -> BinaryTreeNode? {
return self.left
}
}
class BinaryTree {
var root: BinaryTree?
func delete(value: Int, inout at root: BinaryTreeNode?) {
if root != nil {
var aNode: BinaryTreeNode? = BinaryTreeNode(value: 123)
var anotherNode: BinaryTreeNode? = BinaryTreeNode(value: 65)
var aTuple = (current: aNode, parent: anotherNode)
self.delete(45, at: &aTuple.current!.getLeftChild())
self.delete(45, at: &aTuple.current!.left)
}
}
}So, in sentence number 20 I keep getting the error message: "Type of expression is ambiguous without more context", but not in sentence 21. I tried some grouping with parenthesis and the error is still there. Any idea what is going on?
I appreciate your help. Kindest regards.
Tomás Balderas