The bug is real, even the official Apple's guide Linking Data Between Two Core Data Stores crashes on launch on iOS 18.0.
It would help if Apple Engineers could have a look at this solution:
How about manually fetching the corresponding records from Core Data? In the Apple's example, instead of
extension Book {
var feedbackList: [Feedback]? { // The accessor of the feedbackList property.
return value(forKey: "feedbackList") as? [Feedback]
}
}
have something like:
import CoreData
extension Book {
var feedbackList: [Feedback]? { // The accessor of the feedbackList property.
if #available(iOS 18.1, *) {
//iOS 18.1+ usual code (current)
return value(forKey: "feedbackList") as? [Feedback]
} else if #available(iOS 18, *) {
//iOS 18.0-18.1 only code
return fetchFeedbackManually()
} else {
//below iOS 18.0 usual code
return value(forKey: "feedbackList") as? [Feedback]
}
}
private func fetchFeedbackManually() -> [Feedback]? {
guard let viewContext = self.managedObjectContext,
let bookUUID = self.uuid else {
return nil
}
return viewContext.performAndWait {
let request: NSFetchRequest<Feedback> = Feedback.fetchRequest()
request.predicate = NSPredicate(format: "bookUUID == %@", bookUUID as CVarArg)
do {
return try viewContext.fetch(request)
} catch {
return nil
}
}
}
}
It seems to work, but I can't say what the consequences of such an approach are...
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: