From 237a1b648eb143015fe7538a56e018488e2eb667 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 9 Jan 2019 11:58:37 +0900 Subject: [PATCH] Assert on reserved property names --- Sources/CoreStoreSchema.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/CoreStoreSchema.swift b/Sources/CoreStoreSchema.swift index db9914b..0a4b5ba 100644 --- a/Sources/CoreStoreSchema.swift +++ b/Sources/CoreStoreSchema.swift @@ -288,6 +288,10 @@ public final class CoreStoreSchema: DynamicSchema { switch child.value { case let attribute as AttributeProtocol: + CoreStore.assert( + !NSManagedObject.instancesRespond(to: Selector(attribute.keyPath)), + "Attribute Property name \"\(String(reflecting: entity.type)).\(attribute.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(attribute.keyPath)\"" + ) let description = NSAttributeDescription() description.name = attribute.keyPath description.attributeType = Swift.type(of: attribute).attributeType @@ -302,6 +306,10 @@ public final class CoreStoreSchema: DynamicSchema { customGetterSetterByKeyPaths[attribute.keyPath] = (attribute.getter, attribute.setter) case let relationship as RelationshipProtocol: + CoreStore.assert( + !NSManagedObject.instancesRespond(to: Selector(relationship.keyPath)), + "Relationship Property name \"\(String(reflecting: entity.type)).\(relationship.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(relationship.keyPath)\"" + ) let description = NSRelationshipDescription() description.name = relationship.keyPath description.minCount = relationship.minCount