mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-09-03 02:47:19 +02:00
cleanup
This commit is contained in:
@@ -27,10 +27,10 @@ extension Modern.PokedexDemo {
|
|||||||
|
|
||||||
try await Modern.PokedexDemo.dataStack.async.perform { transaction -> Void in
|
try await Modern.PokedexDemo.dataStack.async.perform { transaction -> Void in
|
||||||
|
|
||||||
let json: Dictionary<String, Any> = try self.parseJSON(
|
let json: Dictionary<String, any Sendable> = try self.parseJSON(
|
||||||
try JSONSerialization.jsonObject(with: data, options: [])
|
try JSONSerialization.jsonObject(with: data, options: [])
|
||||||
)
|
)
|
||||||
let results: [Dictionary<String, Any>] = try self.parseJSON(
|
let results: [Dictionary<String, any Sendable>] = try self.parseJSON(
|
||||||
json["results"]
|
json["results"]
|
||||||
)
|
)
|
||||||
_ = try transaction.importUniqueObjects(
|
_ = try transaction.importUniqueObjects(
|
||||||
@@ -57,7 +57,7 @@ extension Modern.PokedexDemo {
|
|||||||
|
|
||||||
let speciesPersistentID = try await Modern.PokedexDemo.dataStack.async.perform { transaction in
|
let speciesPersistentID = try await Modern.PokedexDemo.dataStack.async.perform { transaction in
|
||||||
|
|
||||||
let json: Dictionary<String, Any> = try self.parseJSON(
|
let json: Dictionary<String, any Sendable> = try self.parseJSON(
|
||||||
try JSONSerialization.jsonObject(with: data, options: [])
|
try JSONSerialization.jsonObject(with: data, options: [])
|
||||||
)
|
)
|
||||||
guard
|
guard
|
||||||
@@ -102,7 +102,7 @@ extension Modern.PokedexDemo {
|
|||||||
|
|
||||||
try self.parseJSON(
|
try self.parseJSON(
|
||||||
try JSONSerialization.jsonObject(with: data, options: [])
|
try JSONSerialization.jsonObject(with: data, options: [])
|
||||||
) as [String: Any]
|
) as [String: any Sendable]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
guard !forms.isEmpty else {
|
guard !forms.isEmpty else {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func withMainActorImmediate(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
if #available(iOS 26.0, *) {
|
if #available(iOS 26.0, *) {
|
||||||
|
|
||||||
Task.immediate(operation: task)
|
Task.immediate(operation: task)
|
||||||
}
|
}
|
||||||
else if Thread.isMainThread {
|
else if Thread.isMainThread {
|
||||||
|
|||||||
+34
-29
@@ -842,7 +842,8 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
_ object: O,
|
_ object: O,
|
||||||
_ indexPath: IndexPath?,
|
_ indexPath: IndexPath?,
|
||||||
_ newIndexPath: IndexPath?
|
_ newIndexPath: IndexPath?
|
||||||
) -> Void) {
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.setAssociatedRetainedObject(
|
Internals.setAssociatedRetainedObject(
|
||||||
Internals.NotificationObserver(
|
Internals.NotificationObserver(
|
||||||
@@ -902,7 +903,7 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
internal func registerObserver<U: AnyObject & Sendable>(
|
internal func registerObserver<U: AnyObject>(
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
willChange: @escaping @Sendable (
|
willChange: @escaping @Sendable (
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
@@ -919,19 +920,21 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
didRefetch: @escaping @Sendable (
|
didRefetch: @escaping @Sendable (
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
_ monitor: ListMonitor<O>
|
_ monitor: ListMonitor<O>
|
||||||
) -> Void) {
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
||||||
)
|
)
|
||||||
|
nonisolated(unsafe) weak let weakObserver = observer as Optional
|
||||||
self.registerChangeNotification(
|
self.registerChangeNotification(
|
||||||
&self.willChangeListKey,
|
&self.willChangeListKey,
|
||||||
name: Notification.Name.listMonitorWillChangeList,
|
name: Notification.Name.listMonitorWillChangeList,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor) -> Void in
|
callback: { (monitor) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -942,9 +945,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didChangeListKey,
|
&self.didChangeListKey,
|
||||||
name: Notification.Name.listMonitorDidChangeList,
|
name: Notification.Name.listMonitorDidChangeList,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor) -> Void in
|
callback: { (monitor) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -955,9 +958,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.willRefetchListKey,
|
&self.willRefetchListKey,
|
||||||
name: Notification.Name.listMonitorWillRefetchList,
|
name: Notification.Name.listMonitorWillRefetchList,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor) -> Void in
|
callback: { (monitor) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -968,9 +971,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didRefetchListKey,
|
&self.didRefetchListKey,
|
||||||
name: Notification.Name.listMonitorDidRefetchList,
|
name: Notification.Name.listMonitorDidRefetchList,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor) -> Void in
|
callback: { (monitor) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -980,7 +983,7 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
internal func registerObserver<U: AnyObject & Sendable>(
|
internal func registerObserver<U: AnyObject>(
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
didInsertObject: @escaping @Sendable (
|
didInsertObject: @escaping @Sendable (
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
@@ -1006,20 +1009,21 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
_ object: O,
|
_ object: O,
|
||||||
_ fromIndexPath: IndexPath,
|
_ fromIndexPath: IndexPath,
|
||||||
_ toIndexPath: IndexPath
|
_ toIndexPath: IndexPath
|
||||||
) -> Void) {
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
||||||
)
|
)
|
||||||
|
nonisolated(unsafe) weak let weakObserver = observer as Optional
|
||||||
self.registerObjectNotification(
|
self.registerObjectNotification(
|
||||||
&self.didInsertObjectKey,
|
&self.didInsertObjectKey,
|
||||||
name: Notification.Name.listMonitorDidInsertObject,
|
name: Notification.Name.listMonitorDidInsertObject,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
callback: { (monitor, object, indexPath, newIndexPath) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1030,9 +1034,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didDeleteObjectKey,
|
&self.didDeleteObjectKey,
|
||||||
name: Notification.Name.listMonitorDidDeleteObject,
|
name: Notification.Name.listMonitorDidDeleteObject,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
callback: { (monitor, object, indexPath, newIndexPath) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1043,9 +1047,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didUpdateObjectKey,
|
&self.didUpdateObjectKey,
|
||||||
name: Notification.Name.listMonitorDidUpdateObject,
|
name: Notification.Name.listMonitorDidUpdateObject,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
callback: { (monitor, object, indexPath, newIndexPath) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1056,9 +1060,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didMoveObjectKey,
|
&self.didMoveObjectKey,
|
||||||
name: Notification.Name.listMonitorDidMoveObject,
|
name: Notification.Name.listMonitorDidMoveObject,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
callback: { (monitor, object, indexPath, newIndexPath) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1072,7 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
internal func registerObserver<U: AnyObject & Sendable>(
|
internal func registerObserver<U: AnyObject>(
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
didInsertSection: @escaping @Sendable (
|
didInsertSection: @escaping @Sendable (
|
||||||
_ observer: U,
|
_ observer: U,
|
||||||
@@ -1081,20 +1085,21 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
_ monitor: ListMonitor<O>,
|
_ monitor: ListMonitor<O>,
|
||||||
_ sectionInfo: NSFetchedResultsSectionInfo,
|
_ sectionInfo: NSFetchedResultsSectionInfo,
|
||||||
_ fromIndex: Int
|
_ fromIndex: Int
|
||||||
) -> Void) {
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
"Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread."
|
||||||
)
|
)
|
||||||
|
nonisolated(unsafe) weak let weakObserver = observer as Optional
|
||||||
self.registerSectionNotification(
|
self.registerSectionNotification(
|
||||||
&self.didInsertSectionKey,
|
&self.didInsertSectionKey,
|
||||||
name: Notification.Name.listMonitorDidInsertSection,
|
name: Notification.Name.listMonitorDidInsertSection,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
|
callback: { (monitor, sectionInfo, sectionIndex) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1105,9 +1110,9 @@ public final class ListMonitor<O: DynamicObject>: Hashable, Sendable {
|
|||||||
&self.didDeleteSectionKey,
|
&self.didDeleteSectionKey,
|
||||||
name: Notification.Name.listMonitorDidDeleteSection,
|
name: Notification.Name.listMonitorDidDeleteSection,
|
||||||
toObserver: observer,
|
toObserver: observer,
|
||||||
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
|
callback: { (monitor, sectionInfo, sectionIndex) -> Void in
|
||||||
|
|
||||||
guard let observer = observer else {
|
guard let observer = weakObserver else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import CoreData
|
|||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public protocol ListObserver: AnyObject, Sendable {
|
public protocol ListObserver: AnyObject, SendableMetatype {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `NSManagedObject` type for the observed list
|
The `NSManagedObject` type for the observed list
|
||||||
|
|||||||
Reference in New Issue
Block a user