引用资产目录并从框架中包含资产目录都会创建重复项吗? [英] Does Both Referencing an Asset Catalogue and Including it from a Framework Create Duplication?

查看:75
本文介绍了引用资产目录并从框架中包含资产目录都会创建重复项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处所述, 此处,这是在框架的.xcassets文件,然后在应用程序的 storyboard/XIB 中使用这些图像,是为了直接在应用程序的项目中手动创建对该目录文件的引用.这会将资产放入应用程序的主捆绑包中,并在尝试通过Interface Builder使用资产时避免了此错误:

As discussed here & here, the only apparent way to host re-usable images in a Framework's .xcassets file, then use those images in the storyboard / XIB of an app, is to manually create a reference to that catalog file directly within the app's project. This puts the assets within the app's main bundle, and avoids this error when trying to use them via Interface Builder:

无法加载从笔尖引用的"ImageName"图像 标识符为"BundleName"的捆绑软件

Could not load the "ImageName" image referenced from a nib in the bundle with identifier "BundleName"

不过,我的问题是:这是否会导致在构建时重复资产? iOS是否足够智能,不能将两者的资产都加倍?

My question, though, is: Does this lead to duplication of the assets at build-time? Is iOS smart enough not to double-up assets which are both:

  • 在应用程序的主捆绑包
  • 中引用
  • 包含在嵌入式框架的捆绑包中
  • Referenced in the app's main bundle and
  • Included in the bundle of an embedded framework

如果这确实导致重复,那么还有什么其他方法可以更有效地达到相同的结果?该框架需要嵌入到应用程序中,因为它包含其他可重用的代码,并且资产也必须位于框架的目录中,因为它们也在其他应用程序中使用.

If this does lead to duplication, what other approach can achieve the same result more efficiently? The framework needs to be embedded in the app, because it contains other reusable code, and the assets need to be in the framework's catalog, because they're also used in other apps.

推荐答案

Apple的目标是最小化资产所需的空间,因此资产被合并并压缩到一个名为"Asset.car"的文件中.

Apple's goal is to minimize the space required for assets, so assets are combined and compressed into one file called 'Asset.car'.

当您提交到应用商店时,将启动一个名为应用细化"的过程,该过程将为不同的实际设备创建变体.

When you submit to the app store a process called App Thinning is started that creates variants for different actual devices.

您可以在本地模拟该过程,甚至可以使用第三方工具在"Asset.car"文件中查看.

You can mimic the process locally and with a third-party tools even take a look inside the 'Asset.car' file.

我在此答案中详细描述了整个过程: 使用Xcode 10构建时在iOS10上的像素化​​图像

I described the whole process in detail in this answer: Pixelated images on iOS10 when building with Xcode 10

要亲自测试,请执行以下操作:

To test it myself I did the following:

  • 我创建了一个工作区
  • 我添加了一个框架
  • 我添加了一个应用程序
  • 在框架内,我添加了一个'Media.xcassets'
  • 我从应用程序中引用了此Media.xcassets
  • 我在Media.xcassets中添加了一张名为"Regensburg.jpg"的图片
  • 我在情节提要中使用此图像

然后,执行上面链接的答案中所述的过程,并提取Asset.car文件.

Then I do the process described in my linked answer above and extract the Asset.car file.

使用内部的第三方工具查看时,可以看到该图像仅在其中一次.

When taking a look with the third-party tool inside, one can see that the image is just once there.

好消息:与预期的一样,没有重复发生.

So good news: like expected no duplication happens.

屏幕截图

在屏幕截图中,您可以看到:

In the screenshot you can see:

  • 具有框架和应用程序的Xcode项目结构以及后台的.xcassets

  • Xcode project structure with framework and app as well as .xcassets in the background

使用故事板上的唯一图像

usage of the only image inside in the storyboard

在Finder右下方区域中提取的Assets.car

the extracted Assets.car in Finder in the lower right area

最后在左下角提到的第三方工具,在那里您看到文件仅存在一次

finally the mentioned third-party tool in the lower left area, where you see that the file is there just once

更多信息

就像我的其他答案一样,我建议您看一下此WWDC 2018视频:第227节,优化应用程序资产,

Like in my other answer I would recommend to take a look at this WWDC 2018 video: Session 227, Optimizing App Assets, https://developer.apple.com/videos/play/wwdc2018/227/

这篇关于引用资产目录并从框架中包含资产目录都会创建重复项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆