简体   繁体   中英

Can we add Core Data classes to a framework in iOS?

I am trying to develop a framework out of my existing code base so that it can be used in another app. My app uses Core Data to save some of the data. Now my doubt here is, can we include classes which contain Core Data methods in my framework.

Yes.

As long as you require that any app using your framework must also include the CoreData framework - put it in your documentation / installation instructions.

Otherwise it won't compile :)

Just to add to Dean's answer. It's worth advising against any temptation to include the Core Data framework within your new framework. A framework that includes another framework is known as an "Umbrella Framework".

In the Framework Programming Guide , in the Guidelines for Creating Frameworks , they state:

Don't Create Umbrella Frameworks

While it is possible to create umbrella frameworks using Xcode, doing so is unnecessary for most developers and is not recommended. Apple uses umbrella frameworks to mask some of the interdependencies between libraries in the operating system. In nearly all cases, you should be able to include your code in a single, standard framework bundle. Alternatively, if your code was sufficiently modular, you could create multiple frameworks, but in that case, the dependencies between modules would be minimal or nonexistent and should not warrant the creation of an umbrella for them.

As Dean says, you can document the dependency - for example - in your new framework's README file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM