guard let modelURL = Bundle.main.url(forResource: "MyAppModel", withExtension: "momd") else {
fatalError("Model file not found!")
}
guard let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL) else {
fatalError("Unable to create managed object model!")
}
let entities = managedObjectModel.entities
for entity in entities {
print("Entity name: \(entity.name ?? "")")
print("Attributes:")
for attribute in entity.attributesByName {
print("- \(attribute.key): \(attribute.value.attributeType.rawValue)")
}
print("Relationships:")
for relationship in entity.relationshipsByName {
print("- \(relationship.key): \(relationship.value.destinationEntity?.name ?? "")")
}
print("-----")
}