Xcode: Multiple CoreData models per each target - ios

I am working on a project which contains multiple targets. This project is using CoreData but each target's needs are different enough to where I thought it would be useful to have a separate Core Data models (eg. TargetName.xcdatamodeld) for each target. And all models would share a common entity with the same class file. I would like to know if any other developers have used this pattern?

Related

Custom methods for CoreData classes

I'm trying to conform to the MVC paradigm in my iOS app. My model consists of entities stored in coreData which I have set up using the xcdatamodel file.
I want to add some custom methods to these entities in order to keep the Model part separate from the Controller.
In previous versions of Xcode the autogenerated managedObject classes were added automatically to my project and I could add custom methods to these classes. Now I no longer see these auto genterated classes.
I have selected 'Class Definition' for the codegen.
Do I need to create an additional class for each entity to enable custom methods on those entities? Or is there a better way to go about this.
This is a rather new Xcode feature. Xcode generates the files for you and holds a reference to the generated files. Even the files do not show up in the project, you still can write extensions for the generated classes.
You can find more detailed information in this answer.

How can I have multiple test targets depend on each other across projects?

I have 2 frameworks Core and Extra in separate projects with separate targets for the framework and tests. I have some test data and helper functions in the Core test target that I want to use in the Extra tests, but I do not want to copy the test data files and helper methods to the Extra project. Is there a way for tests targets to depend on other other test targets similar to framework targets in a way that they can import each other's' classes and compiled resources?
Here's a diagram if that didn't make sense.
Core.xcodeproj
Core.framework
Core.test
Extra.xcodeproj
Extra.framework
Extra.test
Extra.framework depends on Core.framework and imports its methods without issues.
Core.test depends on Core.framework; Extra.test depends on Extra.framework. Both test targets can use the framework methods for unit testing without issues.
Let's say I have TestHelper.h|m in Core.test. If I want to use this same class in Extra.test, how do I set up Core.test as a dependency for Extra.test in a way where I can import the class and compiled resources?

iOS framework and separate project have the same framework dependencies

I am creating a framework in Xcode for my iOS app which contains a large set of common classes which are used amongst several projects. Some of these classes have dependencies on other frameworks. However, there are also classes in other projects where I want to use this framework, which share some of the same framework dependencies.
To try simplify with an example:
Framework A: has classes which require Framework B
Project 1: includes Framework A, but has a class which requires Framework B.
I am currently including Framework B in Framework A so that my code will compile. There are two problems:
Once I do this, I can't include Framework B in Project 1, because there is now a duplication of classes.
It sounds like I'm creating an umbrella framework, which is usually discouraged.
Is there a way I can build Framework A in a way that says: "trust these frameworks will be included in any projects that use you, and don't include them yourself"?

How to share files among Xcode Projects

I have made some categories of some classes such as NSArray and NSDictionary. I would like to use these categories in several projects. I may modify the files in any project, and I want all other projects get the updated files.
What's the best way to share files among projects?
I have read this problem and this problem. Someone recommended to add targets into the same project. This is not a good solution in my situation, because my projects are not related to each other, and I have many projects.
In your case you can create a static library and put all of your classes, class methods or sub classes then you can link to your individual projects.
Static libraries provide a convenient mechanism for sharing code among
multiple applications. On iOS, static libraries are the only supported
library type. This document explains how to extract code from your
application into a new static library and how to use that static
library in multiple applications.
Whenever you want to add/edit/remove something you can edit and rebuild your library. Creating the Library and Creating a Static Library in iOS.
When Xcode 6 and IOS 8 released IOS will support frameworks as well.

Is it possible to duplicate an iOS application without duplicating all the code?

I have 3 applications that share a lot of functionality. It is only the content and styling changes between them.
Instead of simply duplicating the project for each app, is there a way to make a "base" application and then have the 3 applications extend this?
Simply duplicating the project would be horrible to maintain, whereas extending a "base" would allow them to all update simultaneously.
I know you could create the project and then copy all files from the old project into the new. This would keep the files up-to-date, however if any files were added or removed, you would have to manually do that.
Have one base project that uses multiple targets. Each target can include a subset of the files in your main project, and/or add their own independent files. Each target can also have its own set of preprocessor defines set up in the build configuration.
You can add more targets to your project in Xcode.
Create a project that builds a static library for the reusable components. You can use an Aggregate target to package any associated resources, such as nib files, storyboards, images, etc.
Your app projects can all then consume the static library and resources. Any changes to the static library will be available to all the dependent projects.

Resources