1

I am developing a Swift iOS app with watch and widget extension.

So far I had a Shared folder where files were checked for all targets that needed them. This works, but I noticed that these files then get compiled for each target.

I would prefer to have the shared core of the app to be built once, and then used as dependency for each of the targets, saving up the compilation time.

What is the good practice for sharing code and assets between app targets?

So far I looked into static library and framework. I ruled out the static library, as I would also like to share assets in addition to code, so that means that I should just create a new framework, and move files in there?

I tried this way, added a framework as dependency to all targets, but it doesn't seem that the framework gets rebuild when a code inside it changes, am I doing it right? Thanks!

Tomáš Kafka
  • 4,405
  • 6
  • 39
  • 52

2 Answers2

0

Frameworks seems to be the right path, the problems I had with getting it built were all caused by this:

I'm not sure why this happens, but one way to solve your issue is to go into your build settings and defining the Framework Search Paths to a folder which contains the frameworks in question. If the frameworks are placed in your project directory, simply set the framework search path to $(SRCROOT) and set it to recursive.

I had to do this in Project Build Settings instead of Target Build Settings.

https://stackoverflow.com/a/31077255/38729

Tomáš Kafka
  • 4,405
  • 6
  • 39
  • 52
0

Latest Apple projects seem to be going the embedded Swift Packages route. You can see examples of this architecture here: https://developer.apple.com/documentation/swiftui/backyard-birds-sample

There's also Ice Cubes, an open-source Mastodon client. This is another example of a great embedded SPM implementation: https://github.com/Dimillian/IceCubesApp

Clément Cardonnel
  • 4,232
  • 3
  • 29
  • 36