[ad_1]
I modified the kind of one of many fields in an entity i created in iOS from a dictionary to a listing and created a brand new model for that entity which is about as default however stored the identical identify, however migration will not be working as at any time when i attempt to iterate that area in a deserialized object it seems to nonetheless be a dictionary because of unrecognized selector error for indexAt i obtain.
I created a subclass of NSEntityMigrationPolicy emigrate a area from a dictionary to string sort ([String : TimerData] -> [TimerData]) with a technique like so:
class SessionTransformationPolicy : NSEntityMigrationPolicy {
@objc func transformTimerRows(information: [String : TimerData]?) -> [TimerData] {
return Array(information!.values).map { orig in
TimerData(previous: orig)
}
}
}
I created a mapping mannequin and set it to this migration coverage, however at any time when i put breakpoints or print statements within the migration coverage it doesnt get executed, i made positive to specify within the mannequin mapping the strategy i created based mostly on on-line sources:
FUNCTION($entityPolicy, “transformTimerRowsWithData:” , $supply.timerRows)
I’ve executed a bunch of analysis into this problem and the one answer i’ve discovered was to enter the app delegate and alter shouldInferMappingModelAutomatically for the container to false however this simply leads to no information being loaded and the migration coverage nonetheless not being referred to as, can somebody inform me what i am doing fallacious?
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(identify: "Mannequin")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = false
container.persistentStoreDescriptions = [description]
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error (error), (error.userInfo)")
}
else {
}
})
return container
}()
[ad_2]
