1

I have to create a reusable framework that is internally use the offline storage for api request, for this i want to use core data, as I am know that for core data using need appdelegate instance. So How can I start this to use core data into my framwork that work seprately from the app that is used this framwork.

Suppose I have create a framwork which will register the application bundle id on server on which it is used. So for this I have to use the api request, and it is important to justify that my api definitely flush the request to the server if somehow request failure need to store the request within the app as offline data so that I will use this to flush the request to the server whenever network reachability found.

Please guide me how start working on it. For Core data management

I have use the following steps:

  1. Make xcdatamodel
  2. Add entities
  3. and make NSManageObject subclass from editor.

found the errors see in the given images

Entity that I have create

NSManageObjects Subclasses

Error in class

Error in extension class

I am working on XCode 9.4.1 with swift 4.2

Sazid Iqabal
  • 409
  • 2
  • 21
  • 1
    You don't need app delegate for CoreData. You can setup the CoreData stack from anywhere. – Cristik Jan 11 '19 at 07:58
  • Thanks @Cristik, for your valuable reply. For this can I make the manager class for core data management does it is work same as appdelegate – Sazid Iqabal Jan 11 '19 at 08:12
  • 1
    Those errors suggest you have codegen set to automatically generate class files, and you have also manually generated them. See [this question and its various answers](https://stackoverflow.com/questions/39657231/xcode-8-generates-broken-nsmanagedobject-subclasses-for-ios-10/40647786#40647786) for more information. – pbasdf Jan 11 '19 at 10:15
  • Thanks @pbasdf for error this is works for me – Sazid Iqabal Jan 11 '19 at 10:17

3 Answers3

4

You don't need appdelegate instance to use core data. Your CoreData model inside framework could be shared between targets/projects.

As this is fairly common thing and there are lot of guides available, here's one that describes the approach step by step.

Brooketa
  • 352
  • 2
  • 9
1

Those errors suggest you have codegen set to automatically generate class files, and you have also manually generated them. See this question and its various answers for more information.

pbasdf
  • 21,386
  • 4
  • 43
  • 75
1

Invalid redeclaration is due to the recreation of the files.

You don't need to create entity subclasses from NSManagedObject

Data model already contains those files and just build once. It should work properly. In short, no need to create entity classes. You can access these entities directly.

Hope it helps you...

Abdul Yasin
  • 3,480
  • 1
  • 28
  • 42