Sharing code between original iOS App and App Extension

前端 未结 3 592
天涯浪人
天涯浪人 2020-12-06 04:26

Sharing class between iOS app and extension app

I want to use a custom class in both my app and the extension app. If I just have the class in the main app folder, t

相关标签:
3条回答
  • 2020-12-06 04:48

    Embedded frameworks are a great way to reuse code between your application and your extension. Having moved some of the code to embedded frameworks will provide us with a great opportunity to write some unit tests around it.

    See section Using an Embedded Framework to Share Code https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

    0 讨论(0)
  • 2020-12-06 05:00

    Nothing should be copied. Just add required files to compile sources for your extension:

    enter image description here

    0 讨论(0)
  • 2020-12-06 05:02

    Just make sure that the files you want to share gets a tick in the section Target Membership.

    Select your file, open the utility panel on the right and tick the appropriate target under Target Membership.

    enter image description here

    0 讨论(0)
提交回复
热议问题