Get rid of the lock. Add comment that Node is main-thread-only; add precondition to init method. Fix #230.

This commit is contained in:
Brent Simmons 2017-12-02 16:12:09 -08:00
parent c73a238359
commit 35cb0fe078
1 changed files with 5 additions and 4 deletions

View File

@ -8,6 +8,8 @@
import Foundation
// Main thread only.
public final class Node: Hashable {
public weak var parent: Node?
@ -17,7 +19,6 @@ public final class Node: Hashable {
public var childNodes: [Node]?
public let hashValue: Int
private static var incrementingID = 0
private static var incrementingIDLock = NSLock()
public var isRoot: Bool {
get {
@ -64,13 +65,13 @@ public final class Node: Hashable {
public init(representedObject: AnyObject, parent: Node?) {
precondition(Thread.isMainThread)
self.representedObject = representedObject
self.parent = parent
Node.incrementingIDLock.lock()
self.hashValue = Node.incrementingID
Node.incrementingID += 1
Node.incrementingIDLock.unlock()
}
public class func genericRootNode() -> Node {