iOS Build app extension base on existing app. How to avoid code duplication?

307 views Asked by At

I have an iOS app that add Sound FX to videos. Now I want to build app extension target to support stocked Photo App. However, I have to duplicate almost every codes from the iOS app. And my solution that I have so far is to put common functions in a shared files and use it for both targets, because some codes in the app linked to AppDelegate and I can't use it in App Extension. Is there any better way to avoid code duplication in this case?

One more question: most extensions that I saw on AppStore only have 1 screen, is there any rules for this?

In my app, I have to let users to choose sounds from folder & library, and it requires navigation controller. But Navigation Controller is not usable in App Extension, should I build my own Navigaion Controller or is there a better way?

1

There are 1 answers

8
dgatwood On BEST ANSWER

As long as you don't need to target iOS 7 or earlier, you can put the common classes into a shared framework and load that framework from both targets. This avoids having two instances of the code on disk.

As an added bonus, because of the way the OS handles shared library loading, all of the actual code pages get shared between the app and the extension, so you aren't wasting RAM, either.