IDE: Version 10.0.0.2397 (develop) built on bajor, 20190419-153353. Commit 6f2fbf4.
Version: Version 10.0.0.2397 (develop) built on bajor, 20190419-153353. Commit 6f2fbf4.
Target (If relevant): iOS
Description:
Unable to use a public weak variable with a struct
. I am trying to create a tree hierarchy with the type TreeNode
type of which I would like to make the parent a weak reference. Typically, you would use a struct definition like:
public class TreeNode<T> {
public var value: T
public weak var parent: TreeNode?
public var children = [TreeNode<T>]()
public init(value: T) {
self.value = value
}
public func addChild(_ node: TreeNode<T>) {
children.append(node)
node.parent = self
}
}
If I add this file Node.swift
in a SharedProject which is referred to by iOS/Toffee project and then try to compile my project
Expected Behavior:
Ability to compile the TreeNode
-class without compiler errors
Actual Behavior:
Getting the error:
E: Flag “Weak” not allowed on this type [/Users/x/Development/Projects/x/x/version-3/config-app/SharedProject/Models/Node.swift (4)]
Steps:
- Create new project
- Add the above
TreeNode
-definition asNode.swift
to this project - Try to compile the project
- Notice compiler error
I am not sure if this is expected behaviour. I have checked the limitations documentation but couldn’t find a reference to it. Also the forum doesn’t give much results when searching for weak var