Remove Core Data from a Xcode project

1

I started developing an application using Core Data in the course of project development and found that Core Data is not the best for the application.

In this scenario, I would like to know how to remove Core Data completely from my application and continue the development of it without it.

    
asked by anonymous 29.09.2015 / 14:24

1 answer

1

As you have not specified whether it's Swift or Objective-C, I'll kick that it's Objective-C. But the process in Swift is similar.

  • Select the project in Project Navigator - > Build Phases and Link Binary With Libraries remove CoreData.framework
  • (Skip this step if it is Swift) Look for the .pch file for your project. Usually the default is: [Your project name] -Prefix.pch . Remove the line from #import <CoreData/CoreData.h>
  • Delete any *. Model file.
  • No AppDelegate.h delete the following properties and methods (Swift are lazy var of same name):

    • @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
    • - (void)saveContext;
      - (NSURL *)applicationDocumentsDirectory;
  • (Skip this step if it is Swift) In AppDelegate.m remove @synthesize from the properties you just removed:

    • @synthesize managedObjectContext = _managedObjectContext; @synthesize managedObjectModel = _managedObjectModel; @synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
  • Still in AppDelegate.m delete the following methods:

    • saveContext managedObjectContext managedObjectModel persistentStoreCoordinator applicationDocumentsDirectory
  • Finally, even in AppDelegate.m , within method applicationWillTerminate remove the call from method [self saveContext]
  • That's right, you got rid of CoreData!

        
    02.10.2015 / 16:28