2

I wanted to add a WatchKit Extension (with SwiftUI supported on iOS13+) to my existing app (target iOS12) while keeping both codebase separated (two repos).

  • How can I separate the WatchKit Extension code from the Mobile One?
  • Will my Watch App with SwiftUI only work for users with WatchOS 6 and iOS13 without affecting the existing users with iOS12?
  • How about the app binary size increase?

Thanks for reading!

Ouadie
  • 13,005
  • 4
  • 52
  • 62
  • Did my answer solve your problem? If so, please accept it so that the answer is closed. If not, please let me know what is missing. – Reinhard Männer Feb 19 '20 at 12:25
  • Thanks for your answer. It didn't answer my question - for the size I wanted to know how to compare both the size of the app with and without the watch extension. For splitting the codes creating and importing the same files won't fix the decoupling issue I'm trying to solve – Ouadie Feb 19 '20 at 18:15

1 Answers1

2

I am not sure if there is a simpler solution, but this one should work:

Separation of both apps:

If you open in Xcode the Source Control navigator, you see that Branches, Tags and Remotes belong to a main entry in the Project navigator, i.e. to a Xcode project. So in order to have separate repos, you need separate Xcode projects to which you can assign separate repos.
You can however have multiple projects in one workspace, so that all files are available in this workspace.
To have one standalone app, and one app with a watch extension, just setup a workspace with your standalone app, and add another new project. This new project needs all files of the original app plus the watch extension.
Since you need files from one project also in the other, you could drag them from one project to the new one, but then they will be copied (a green + badge is shown during dragging). Usually this is not what you want, since you usually don’t want to maintain two copies separately. Instead, you can show such a file in the finder, and then drag it from the finder to the new project. In this case, you have the option only to copy the reference.

Independence of both apps:

Since you have two separate projects, you can set the deployment target in the target’s build settings as required.

Size:

Each project will get separate products, the standalone app only an xxx.app, and the new project xxx.app, Watch.app, and Watch Extension.appex. So there should be no overhead.

EDIT (due to the comment of Ouadie in his question):

I am not sure if I understand your problem:
With the procedure above, you get a single workspace with two separate projects that share part of the files.
The „mobile project“ is the same as you use right now. It has only a single target (despite of test targets) that is built exclusively with the sources required. It has thus the same size as now.
The „watch project“ is new. It has 3 targets, the „mobile“ target, the Watch target, and the Watch Extension target (despite of test targets). It is built with the shared sources, and the additional watch extension sources. Its size is thus larger, but the increase depends of course on your sources.
Since you have 2 repos, the projects are decoupled, but both repos share some files. If you want to decouple them completely, you could copy the files from your current project to your new project (instead of copying only references), but then you had to maintain 2 copies.
I hope this helps!

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116