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:
parent
c73a238359
commit
35cb0fe078
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue