mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-11-18 06:38:28 +01:00
cleanup
This commit is contained in:
1 parent
838637f29f
commit
10ac228867
8 files changed
+84
-40
No files matched your search
@@ -554,11 +554,18 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
context.undoManager = nil
|
||||
}
|
||||
else if context.undoManager == nil {
|
||||
|
||||
Internals.mainActorImmediate {
|
||||
|
||||
context.undoManager = UndoManager()
|
||||
let undoManager: UndoManager
|
||||
if Thread.isMainThread {
|
||||
|
||||
undoManager = MainActor.assumeIsolated { UndoManager() }
|
||||
}
|
||||
else {
|
||||
|
||||
undoManager = DispatchQueue.main.sync {
|
||||
MainActor.assumeIsolated { UndoManager() }
|
||||
}
|
||||
}
|
||||
context.undoManager = undoManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ extension ListSnapshot {
|
||||
|
||||
public let sectionID: SectionID
|
||||
|
||||
public let itemIDs: [NSManagedObjectID]
|
||||
public let itemIDs: [ItemID]
|
||||
|
||||
|
||||
// MARK: RandomAccessCollection
|
||||
@@ -79,7 +79,7 @@ extension ListSnapshot {
|
||||
public subscript(position: Int) -> ObjectPublisher<O> {
|
||||
|
||||
let itemID = self.itemIDs[position]
|
||||
return self.context.objectPublisher(managedObjectID: itemID)
|
||||
return self.context.objectPublisher(managedObjectID: itemID.managedObjectID)
|
||||
}
|
||||
|
||||
public func index(_ i: Index, offsetBy distance: Int) -> Index {
|
||||
@@ -100,7 +100,7 @@ extension ListSnapshot {
|
||||
public subscript(bounds: Range<Index>) -> ArraySlice<Element> {
|
||||
|
||||
let itemIDs = self.itemIDs[bounds]
|
||||
return ArraySlice(itemIDs.map(self.context.objectPublisher(managedObjectID:)))
|
||||
return ArraySlice(itemIDs.map({ self.context.objectPublisher(managedObjectID: $0.managedObjectID) }))
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ extension ListSnapshot {
|
||||
}
|
||||
self.sectionID = sectionID
|
||||
self.itemIDs = listSnapshot.itemIDs(inSectionWithID: sectionID)
|
||||
.map({ $0.managedObjectID })
|
||||
self.context = context
|
||||
}
|
||||
}
|
||||
|
||||
+16
-18
@@ -38,7 +38,7 @@ import Foundation
|
||||
```
|
||||
- Important: Do not use this class to store thread-sensitive data.
|
||||
*/
|
||||
public final class UserInfo: Sendable {
|
||||
public final class UserInfo: @unchecked Sendable {
|
||||
|
||||
/**
|
||||
Allows external libraries to store custom data. App code should rarely have a need for this.
|
||||
@@ -55,17 +55,15 @@ public final class UserInfo: Sendable {
|
||||
|
||||
get {
|
||||
|
||||
return self.data.withLock { (info: inout _) in
|
||||
|
||||
return info[key]
|
||||
}
|
||||
self.lock.lock()
|
||||
defer { self.lock.unlock() }
|
||||
return self.data[key]
|
||||
}
|
||||
set {
|
||||
|
||||
return self.data.withLock { (info: inout _) in
|
||||
|
||||
info[key] = newValue
|
||||
}
|
||||
self.lock.lock()
|
||||
defer { self.lock.unlock() }
|
||||
self.data[key] = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,16 +82,15 @@ public final class UserInfo: Sendable {
|
||||
*/
|
||||
public subscript(key: UnsafeRawPointer, lazyInit closure: () -> any Sendable) -> any Sendable {
|
||||
|
||||
return self.data.withLock { (info: inout _) in
|
||||
|
||||
if let value = info[key] {
|
||||
|
||||
return value
|
||||
}
|
||||
let value = closure()
|
||||
info[key] = value
|
||||
self.lock.lock()
|
||||
defer { self.lock.unlock() }
|
||||
if let value = self.data[key] {
|
||||
|
||||
return value
|
||||
}
|
||||
let value = closure()
|
||||
self.data[key] = value
|
||||
return value
|
||||
}
|
||||
|
||||
|
||||
@@ -104,5 +101,6 @@ public final class UserInfo: Sendable {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let data: Internals.Mutex<[UnsafeRawPointer: any Sendable]> = .init([:])
|
||||
private var data: [UnsafeRawPointer: any Sendable] = [:]
|
||||
private let lock = NSRecursiveLock()
|
||||
}
|
||||
Reference in new issue
Block a user