4

I am using Core data in my project and using directly NSManagedObject in the viewControllers with the help of fetchResultController.
But as per new clean code architecture or VIPER approach, it is saying use PONSO or NSOject instead of NSManagedObject in the views or presenter classes.

Can anyone give me pro and cons for the NSManagedObject vs NSObject in above scenario?

Pradeep Kachhawaha
  • 6,589
  • 2
  • 14
  • 13

1 Answers1

2

I made a list of pros for the two approaches:

Keep NSManagedObject approach:

  1. It's simpler
  2. It's faster ( NSManagedObjects only load their properties from memory if needed )
  3. You're able to use NSFetchedResultsController: This may be a personal point, but in my apps i make heavy use of NSFetchedResultsController, because it's just so easy to keep the interface of a Table View persistent with the data.

VIPER approach: ( Decode every NSManagedObject to a PONSO )

  1. You get the flexiblity to switch your storage backend very easily. I.e. if you'd wanna switch from core data to a .plist file ( probably not the best idea ).
  2. You can use multiple data sources: I.e. store the currently signed in user's profile in Core Data but store his access token in keychain. Other objects could simple use the PONSO, which would contain the data from both sources.
  3. Tests: Testing your Interactors is a lot easier if you're able pass them a PONSO instead of having to create a NSManagedObjectContext, NSFetchRequest and NSManagedObjects.
  • Thanks Lukas. After research I opted VIPER approach as I am using Parse as server side and its having PFObject and Coredata is having NSManagedObject. So its better to get PONSO in the Viewcontroller whatever is coming from Parse or ManagedObject, and have flexibility to switch parse to other backend. – Pradeep Kachhawaha Mar 10 '15 at 13:11