Referencing App Object Across Multiple Build Targets iOS - ios

I need to make several versions of an iOS application each with a different target and name. Most of the differences between the applications are in the applications resources and not the source code. I am trying to share as much source code across versions as possible.
My issue arises when I try to access the application object in a version which does not have the same name as the original. For instance, I have two versions of the application named UserApp and UserApp2 and the following code which references the data store:
var user = UserApp.User
When I try to run this code in the UserApp2 target, it throws an error saying UserApp is undefined.
My question is: How can I make this code load the proper application object depending on what target is currently running? I would like a solution that can be used across all targets without the need to change code.
EDIT: The UserApp object is an XCDataModel.

The UserApp class might not be added in all of your application targets. verify the target membership for the class.

Related

Is it possible to add script creating realm database from JSON to my project?

I want to bundle read-only realm database with my app. I was able to do this by following this tutorial. There are couple of issues with this solution though. The fact that I had to create another xcode project for it comes with various cons like:
I have to keep duplicates of my classes inheriting from Realm Object and manually keep them in sync between two projects
I have to open another project each time I want to create new updated realm database
It would be weird to keep 2 xcode projects in one git repository
My question is: Is it possible to add some kind of standalone script to my project that would have access to my realm objects and realm library that I could manually run from time to time instead of having to do that in another project?
I was looking into adding playground and running it from there, but I think that swift package manager is currently bugged in a way that doesn't allow to build such a solution as I'm getting This will result in duplication of library code. error that cannot be fixed with DISABLE_DIAMOND_PROBLEM_DIAGNOSTIC flag.
Is there some other solution than having to do it within another project? I think there must be a way to run utility scripts like this - that aren't strictly part of the app, but surprisingly I couldn't find any so far.

Is there is any way to create a IOS app as build for another app?

I have an IOS app which holds lot of Configuration settings to use the app and also this app is used in 5 warehouses, settings will be differ from one warehouse to another warehouse. So it becomes more painful for the users using this app.. Even ever they install the app then need to set the configuration settings.
So my problem is If i hardcode the settings value, it is very difficult to maintain the code for all the different warehouse. if i do small change in my app have to change in all of the 5 source code.. Even if i decide to maintain 1 code .. i have to change the setting value every time before setting the build.. It is more painful for me.
so my question is..
Is there any way to run a app and set values in configuration settings. And generate this setting app as a build ?? i don't know it will workout or not please share me some ideas..
If I understand correctly, you want to have 1 source code and there is possibility to create different Targets. Each target can have it's own configuration plist file and you can set also different preprocessor macros for each target.
How to use preprocesor macros you can see here: How can I differentiate between multiple targets in xcode at runtime
How to create targets you can see here: Add preprocessor macro to a target in xcode 6
One more possibility (besides targets) is to create a shared library and if you want to apply some configs after installation you can prompt user to download one from a server (for instance)
Yes, you can create different schemas.
For example, you can create an application for Development, Staging, Production.
You can have configurations in plist file and make it variable according to the schemas.
When your application opens it will take the values according to the schema with which it was built.
Follow this guide to create different schemas.
Also, you can integrate Fastlane to generate builds easily with different schemas with simple commands.
Yes you can have one app with different targets and schema. Then just google it there's many articles about.

Build variants (different files for different brands) in Xcode / iOS

Android has very good tools for creating different variants of an app (for example, the exact same code but with a different logo). You just create a different flavour and put a different image for each flavour's directory. How do I achieve this in Xcode? The information I have found on the web is very bad. I tried creating a new target for my project but that created a new storyboard, AppDelegate etc. It just created a new app altogether. I want different resource folders for different brands of the app. I'm using Swift.
You're not likely to get the same kind of setup you could have with Android. There are a bunch of features you could use individually or in combination. rmaddy's comments are good. Another option is creating additional schemes and setting the properties of the project for each one. The important thing to keep in mind is that the simplest solution may not look the way you're expecting.

Exceptions in my iOS Framework Show Private Code?

I'm building an iOS framework where only a single header file is exposed, and the rest of the code is private. Within Xcode I have all objective-c exception breakpoints on, so normally when there's an exception I'm brought to where it occurred in the code.
During testing in a totally new project that is using this framework I created, every now and then when an exception is raised inside the framework, I'm brought to the otherwise private framework code, which is obviously not what I want.
I think this may be because the actual raw framework code/project exists in my environment and wouldn't occur for another person using my framework without access to the actual files, but unfortunately I don't have any way to currently test this theory. Does anyone know if this is something I need to be handling in order to truly keep the project files private that I intent to, or is this just a function of having the code exist locally?
I was able to get in another dev environment with a fresh project to drop in the framework and force an internal framework crash and it appears that if the otherwise private framework files exist on the same environment and a crash occurs when you have objective-c exception breakpoints enabled it will open the private framework file in question, BUT if you don't have those private framework files (which consumers of your framework wouldn't) you will simply be taken to the normal crash/stack trace view like below:

Using one xcdatamodelId in two app

I created one project with core data that will work with unchangeable database. And I don't want to write code in this project , that will programmatically populate this database. So, I create second project with core data, add existing xcdatamodel from first project without copying(only references). There i populate my database, open it with mozilla plug-in and it successfully filled. Then I copy ,my *.sqlite file and manually replace it with old file in first project. It causes error:"The model used to open the store is incompatible with the one used to create the store". But I use for both files the same xcdatamodelid. Where my error?
Sorry for my english, I really need help.
P.S. when I open sqlite file from first project and second (with commented code of populate base) in FileMerge - second is already empty. I appreciate any advice or help.
Karoly S nicely answers the question. I have a hint that I frequently employ that may prevent this out of sync situation. Instead of two Xcode projects trying to share one model file, just create one Xcode project with two targets. Each target will use the same model file, any class definitions derived from that model, and possibly other code. My second target is a Mac OS command line program that generates the database, while my first target continues to be the iOS app that reads that database. The Mac OS target will overwrite the database file in a project subdirectory, ensuring it's up-to-date. If I make any changes to the model, Xcode knows to update both targets.
Did you change your Model Definitions in any way? The error you are seeing is because there is some difference between the model from when you created it, and again from when you are trying to reference it. Are you running on the simulator? Try to delete both of your apps to clear the data related to it, as it might be out of date. Afterwards simply rebuild both of your projects as that will update your core data database.
EDIT: To clarify a bit more, your core data model is out of sync, this is generally caused by you building and running an app, and a database being created, then redefining your object model, this can be done in a variety of ways, most likely caused by the addition of an attribute or entity. So when you are trying to load the database there are fields that the app and core data are looking for, but are not there because they did not exist when the database was created. I hope this helps.

Resources