Central CRUD class

Hi guys, love the tutorial got me grounded quickly. I have a topic for discussion and wanted to get some opinions. I typically (in other languages) write a class that performs all of my CRUD operations to avoid writing all the details of saving a entity in view controller classes in the case of IOS. The tutorial doesn’t go into this but I expect this is a next level topic anyway, but my question is assuming I want to do this what would you consider the best practice, would you add these functions to the entity class or create a seperate static class that has these functions?

Thanks in advance for thoughts

@pavelar Thanks very much for your question!

You raise an interesting scenario. Some deal with this situation by using a Singleton class which contains all the methods for CRUD operations. Is this something recommended? Personally, as well as many iOS authorities who know much more than me tell people to avoid using Singletons, because of the extra baggage they bring.

Because typically each entity is unique, I personally would recommend that you keep these CRUD operation methods within the entity’s ManagedObjectSubclass. You are allowed to customize those classes, and it also helps keep your code outside of your ViewController. :slight_smile:

I hope this helps!

All the best!

This topic was automatically closed after 166 days. New replies are no longer allowed.