Я пытаюсь программно создать новый атрибут для уже существующей сущности в swift.
Это мой код:
let model = NSManagedObjectModel()
var properties = Array<NSAttributeDescription>()
let remoteURLAttribute = NSAttributeDescription()
remoteURLAttribute.name = "\(foundArray[indexPath.row]) id"
remoteURLAttribute.attributeType = .stringAttributeType
remoteURLAttribute.isOptional = false
remoteURLAttribute.isIndexed = true
properties.append(remoteURLAttribute)
entity?.properties = properties
model.entities = [entity!]
Приложение всегда вылетает с этой ошибкой:
Завершение работы приложения из-за неперехваченного исключения «NSInternalInconsistencyException», причина: «Невозможно изменить неизменяемую модель».
Как я могу это исправить?