Same code base in different apps [closed]

2019-09-19 22:59发布

问题:

Here's my problem: Today my company has an app that communicates with a specific server, but we received demands to develop this same App for different servers, so a few things need to be changed in the App (like the URL to call and the logo).

I do not want to create a whole new application with 99% of the code the same in my Xcode just to do that, because it would be really difficult to develop new stuff.

I'm wondering if it's possible to maintain the same base code with just small changes to different applications.

Hope I made myself clear, thank you.

回答1:

Just to answer my own question, I just found this guide:

https://itexico.com/blog/iOS-Mobile-Development-Using-Xcode-Targets-to-Reuse-the-Code

Different targets and preprocessor macros are just what I needed, pretty sweet!



回答2:

For something like this, I'd suggest using easy-to-manipulate stuff like plists and so on to make a core app like a framework that would be able to read an XML for example, and parse its data into different fields of your Plist and apply the settings based on that data for every new app that you have.

So, you should have items like url and logo, etc. in your settings Plist, and getting to read them in the app rather than setting values manually inside the app. This way, you'll be able to drop different image files called logo.png for each app, or edit the value for url in your Plist, and the app will read the value from the Plist.

However keep in mind that Plists are good if you don't have a giant list of items, because they can be slow if you get a really big one, but they're so quick and handy for average number of items.

I hope this helps.



标签: ios xcode