Преглед изворни кода

combine compactMap operations; use functional approach and assign the return value to the perform method

Marvin Polscheit пре 11 месеци
родитељ
комит
414a039655

+ 0 - 12
Trio/Resources/InfoPlist.xcstrings

@@ -457,18 +457,6 @@
         }
       }
     },
-    "NSCalendarsFullAccessUsageDescription" : {
-      "comment" : "Privacy - Calendars Full Access Usage Description",
-      "extractionState" : "extracted_with_value",
-      "localizations" : {
-        "en" : {
-          "stringUnit" : {
-            "state" : "new",
-            "value" : "To create events with BG reading values, so that they can be viewed on Apple Watch and CarPlay"
-          }
-        }
-      }
-    },
     "NSCalendarsUsageDescription" : {
       "comment" : "Privacy - Calendars Usage Description",
       "extractionState" : "extracted_with_value",

+ 7 - 6
Trio/Sources/Modules/Stat/StatStateModel+Setup/GlucoseStatsSetup.swift

@@ -2,7 +2,7 @@ import CoreData
 import Foundation
 
 /// A thread-safe value type to hold glucose data without Core Data dependencies
-struct GlucoseReading {
+struct GlucoseReading: Sendable {
     let value: Int
     let date: Date
 }
@@ -169,12 +169,13 @@ extension Stat.StateModel {
 
         // Extract the thread-safe glucose readings
         let privateContext = CoreDataStack.shared.newTaskContext()
-        var glucoseReadings: [GlucoseReading] = []
 
-        await privateContext.perform {
-            let readings = glucoseIDs.compactMap { privateContext.object(with: $0) as? GlucoseStored }
-            glucoseReadings = readings.compactMap { reading in
-                guard let date = reading.date else { return nil }
+        // Map into Sendable struct
+        let glucoseReadings: [GlucoseReading] = await privateContext.perform {
+            // Get NSManagedObject on private context and map into GlucoseReading struct
+            glucoseIDs.compactMap { id -> GlucoseReading? in
+                guard let reading = privateContext.object(with: id) as? GlucoseStored,
+                      let date = reading.date else { return nil }
                 return GlucoseReading(value: Int(reading.glucose), date: date)
             }
         }