ios - Share Xcode Asset Catalog between targets without duplicate the resources file - Stack Overflow

admin2025-04-16  2

I‘m now using a xcassets for my main app, and I want to use these assets in my extension target. I add the extension to the target membership of xcassets.

It works fine but when I check the product size, it became larger and it seems to have copied the asset file again to the extension.

Is there any way to still use the asset catalog, and share the resources without extra copy?

I‘m now using a xcassets for my main app, and I want to use these assets in my extension target. I add the extension to the target membership of xcassets.

It works fine but when I check the product size, it became larger and it seems to have copied the asset file again to the extension.

Is there any way to still use the asset catalog, and share the resources without extra copy?

Share Improve this question edited Feb 3 at 17:17 HangarRash 15.1k5 gold badges20 silver badges55 bronze badges asked Feb 3 at 14:38 Perry WangPerry Wang 2092 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Is there any way to still use the asset catalog, and share the resources without extra copy?

No. The entire nature of an extension is that it is completely independent from the host app; it is, in effect, a completely independent mini-app on its own. It cannot magically "reach into" the host app's bundle; that is why including the asset catalog causes the asset catalog to be compiled separately into the host app bundle and the extension bundle.

What you can do, of course, is have the app write the resources into a shared app group directory, where the extension can find them, in exactly the same way you would share any resource between an extension and its host app. But this would have disadvantages of its own; for example, it would mean that the extension would not work properly until the app had run once.

转载请注明原文地址:http://www.anycun.com/QandA/1744766128a87317.html