Skip to content
New issue

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

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

Already on GitHub? # to your account

Better API for creating entity descriptions and inserting managed objects #87

Closed
jessesquires opened this issue Jun 5, 2016 · 3 comments
Assignees
Milestone

Comments

@jessesquires
Copy link
Owner

jessesquires commented Jun 5, 2016

Would like to improve the existing entity() func, and provide a better/easier way to create an entity description and insert managed objects.

Daniel has great approaches outlined in this talk:
https://realm.io/news/tryswift-daniel-eggert-modern-core-data/

I think we should do this, or something similar.

@jessesquires jessesquires added this to the 5.0.0 milestone Jun 5, 2016
@jessesquires jessesquires mentioned this issue Jun 5, 2016
3 tasks
@jessesquires
Copy link
Owner Author

Generate entity name via "\(self.dynamicType.self)" ?

@jessesquires
Copy link
Owner Author

Could implement this in v4.x and keep existing entity() marked as deprecated, then we can remove this v5.0

@jessesquires jessesquires self-assigned this Jun 6, 2016
@jessesquires jessesquires removed this from the 5.0.0 milestone Jul 5, 2016
@jessesquires
Copy link
Owner Author

jessesquires commented Jul 22, 2016

Draft design:

protocol CoreDataEntityProtocol {
    static var entityName: String { get }

    static var defaultSortDescriptors: [SortDescriptor] { get }
}

extension CoreDataEntityProtocol where Self: NSManagedObject {

    static func defaultEntityName() -> String {
        return "\(Self.self)"
    }

    static var fetchRequest: NSFetchRequest<Self> {
        let request = NSFetchRequest<NSManagedObject>(entityName: entityName)
        request.sortDescriptors = defaultSortDescriptors
        return request as! NSFetchRequest<Self>
    }

    static func entity(context: NSManagedObjectContext) -> NSEntityDescription {
        return NSEntityDescription.entity(forEntityName: entityName, in: context)!
    }
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant