Gustavo
Gustavo

Reputation: 914

Dependency management in iOS

I have the following scenario:

I'm developing an iOS application that is being used for different companies. For each company, there are a few differences:

The best approach is to make a single code and then, override some values and assets for each one of the applications. In Android I can easily achieve this by creating a library module (with the core of the app) and an application module for each company (with no Java code) just by overriding the resources.

I'm trying to develop the same structure at XCode, but the way of doing it is not clear for me. After a brief research, I considered some options: Framework, Static Library and Subprojects.

Which one would be the correct way of doing it? Should I consider using a Dependency/Package Manager (like Swift Package Manager, CocoaPods or Carthage)?

These package manager are git-dependent? Because I'm working with SVN, and switching to Git is not viable at this point.

Project settings:
XCode 9
Swift 4

Upvotes: 0

Views: 113

Answers (2)

Priyam Dutta
Priyam Dutta

Reputation: 702

You can go with Static Framework for developing this kind of projects. Now, Static framework has its own ups and downs.

https://www.raywenderlich.com/65964/create-a-framework-for-ios

  • Create a Core Module Framework for all the common classes that will be shared for different Apps as Company1Extenssion, Company2Extenssion.
  • Now include this Core module framework into the individual projects by creating respective workspaces.
  • The individual extended projects will hold their own Assets, App Icons, App Name.
  • Note, one of the cons of this approach is you can't include pods in it. You have to go for Carthage or Git sub modules for any Third party library.
  • One of the Pros of this approach is you can maintain Code security for the core module by specifying the functions or classes to be extended to the Extensions.

Note: During release of the app don't forget to ensure the proper payload structure of the ipa file.

Upvotes: 0

Kevin Machado
Kevin Machado

Reputation: 4187

I recommend you to use targets.

Let me show you how I handle this hierarchy with my assets / settings.

Assets


My Assets directory

Assets directory

  • Common folder contains the common images
  • Company1 folder contains the images / colors / certificates

You have to change the Target Membership for the Company1 > Images by selecting only the target that it does need to refer to.

Target settings

For example, common > Assets needs to refer to all targets.

Code


You can do the same with your code if you need to do something different in each targets.

Personally, I use the power of extension to split the code in different source files to be able to refer to different targets.

Refer this file to the Company1 target

extension FirstViewController {

    func doSomething() {
        // implement this method for the company 1
    }

}

Refer this file to the Company2 target

extension FirstViewController {

    func doSomething() {
        // implement this method for the company 2
    }

}

Refer this file to all targets

class LandingEmptyViewController {

    func foobar() {
        self.doSomething()
    }

}

You can also pass some flags per target in the Build Settings

Using those solutions, you will be able to do the same of in Android.

Upvotes: 3

Related Questions