Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes attribute creation for models with subentities. Only creates th… #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions Seam/Seam/SMStoreChangeSetHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@ class SMStoreChangeSetHandler {
}

func addExtraBackingStoreAttributes(toEntity entity: NSEntityDescription) {
let recordIDAttribute: NSAttributeDescription = NSAttributeDescription()
recordIDAttribute.name = SMLocalStoreRecordIDAttributeName
recordIDAttribute.optional = false
recordIDAttribute.indexed = true
recordIDAttribute.attributeType = NSAttributeType.StringAttributeType
entity.properties.append(recordIDAttribute)
let recordEncodedValuesAttribute: NSAttributeDescription = NSAttributeDescription()
recordEncodedValuesAttribute.name = SMLocalStoreRecordEncodedValuesAttributeName
recordEncodedValuesAttribute.attributeType = NSAttributeType.BinaryDataAttributeType
recordEncodedValuesAttribute.optional = true
entity.properties.append(recordEncodedValuesAttribute)
let attributes = entity.attributesByName

if attributes[SMLocalStoreRecordIDAttributeName] == nil {
let recordIDAttribute: NSAttributeDescription = NSAttributeDescription()
recordIDAttribute.name = SMLocalStoreRecordIDAttributeName
recordIDAttribute.optional = true
recordIDAttribute.indexed = true
recordIDAttribute.attributeType = NSAttributeType.StringAttributeType
entity.properties.append(recordIDAttribute)
}
if attributes[SMLocalStoreRecordEncodedValuesAttributeName] == nil {
let recordEncodedValuesAttribute: NSAttributeDescription = NSAttributeDescription()
recordEncodedValuesAttribute.name = SMLocalStoreRecordEncodedValuesAttributeName
recordEncodedValuesAttribute.attributeType = NSAttributeType.BinaryDataAttributeType
recordEncodedValuesAttribute.optional = true
entity.properties.append(recordEncodedValuesAttribute)
}
}

func changeSetEntity() -> NSEntityDescription {
Expand Down Expand Up @@ -103,9 +109,19 @@ class SMStoreChangeSetHandler {
func modelForLocalStore(usingModel model: NSManagedObjectModel) -> NSManagedObjectModel {
let backingModel: NSManagedObjectModel = model.copy() as! NSManagedObjectModel
for entity in backingModel.entities {

if entity.superentity != nil { // only add to super-entities, not the sub-entities
continue
}
if entity.name == SMLocalStoreChangeSetEntityName {
continue
}

self.addExtraBackingStoreAttributes(toEntity: entity)
}
backingModel.entities.append(self.changeSetEntity())
if backingModel.entitiesByName[SMLocalStoreChangeSetEntityName] == nil {
backingModel.entities.append(self.changeSetEntity())
}
return backingModel
}

Expand Down