After creating an updated version of data model and only adding a few new attributes to one entity I'm unable to access the new attributes in my swift view controller files.
In Xcode 10 targeting iOS 12 I've changed the selected Core Data model to the updated version. As I understand it light migration is already enable by default. This seems to be reflected in my console messages when I do my fetch request that shows the new attributes. However, I'm unable to access the new attributes in code within my view controller swift files. I tried adding 'true' flags to MigrateStoreAutomatically and InferMappingModuleAutomatically in my Core Data stack class NSPersistantStoreDescription and am still unable to access the new attribute in code.
// ATTEMPT @ ENABLING LIGHT MIGRATION IN CORE DATA
lazy var storeDescription: NSPersistentStoreDescription = {
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = false
return description
}()
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "123ABC")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
// CODE IN SWIFT VIEW CONTROLLER TRYING TO ACCESS NEW ATTRIBUTE
var selectedTextPhrase: TextPhrase!
self.selectedTextPhrase.imageURL = "WHAT HAPPENED TO MIGRATION?"
self.selectedTextPhrase.favorite = true
Value of type 'TextPhrase?' has no member 'imageURL' is the message I receive.
The "imageURL" is a new optional attribute that I added to an entity and is a String. The "favorite" attribute is a Boolean and a pre-existing attribute from the prior Core Data model version. I am able to access the "favorite" attribute and not the "imageURL." When typing the code "imageURL" doesn't appear an auto-complete option as the original attributes of the entity from the original Core Data model do.