xxtesaxx xxtesaxx - 1 year ago 108
iOS Question

How to subproject or target multiple app equivalents in iOS 10 / Xcode 8 / Swift 3

it's been a while since I last developed for iOS. I think it was before Swift came out. However, this doesn't matter. I'm curious about a thing I shall do for my employer.

We have a product which makes use of GPS tracker and besides a webapp, we now also want to offer mobile apps. I already created the Android version of our app. For this, I used one base project, in which I implemented all the functionality (e. g. function 1 and function 2).

I then created two other projects, which have the base project as a dependency. These two projects are my actual apps. The App class overwrites the base app class, which has two abstract methods "hasFunction1" and "hasFunction2" which both return a boolean value which I use in the base app to provide a certain piece of functionality.

I also can easily let the App class of each app return classes for different cases because these classes (subclasses of activities for example) have their basic functionality implemented in the base project whereas the app project only extends or overrides a certain piece of functionality.

Now I want to do the same for iOS but here things are different. You have Storyboards which directly go to a certain class and I have no clue if I should create multiple projects (like in the android app) or if it would be better to use targets instead.

What is your opinion on this? Please keep in mind that my apps are almost the same. The only differences are the names as well that sometimes App 1 has enabled a piece of functionality which App 2 has not (but might have in the future)

Whats the best approach for this kind of project? I have no idea how to tackel it in iOS


I just got an idea and I'd like to hear you opinion on this:

  • Have a protocol, a simple one which for example has only one method returning a boolean

  • In the base class, check if self is implementing the protocol and call the method on it if so. Use the return value do determine if a function is available

  • Create multiple targets, one for each of my apps

  • In each target, create a extension for my base class which implements the protocoll

After a quick test in my playground, this seems to work as I expect but I'm still not sure if I should create a framework, multiple projects and/or just different targets :/

enter image description here

Answer Source

I figured out, that I basically have two options to achieve what I want. The first one is the one I already mentioned in the update of my original post:

I can create a protocol and in the core, I make a check if self is an instance of the protocoll and if so, call a method on the protocol. In my subprojects, I then simply create an extension for my class, which now implements my protocol.

The second way I figured out is, that I could use preprocessor macros and/or environment variables.

I hope this answer helps somebody else with identical problems as me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download