How Many Images Can/Should you Store in xcassets in Xcode?

允我心安 提交于 2021-01-04 08:05:00

问题


I'm trying to store a lot of images for a project in xcassets. Around 2,000. However, they are all very small/highly optimized at only around 3-5kB each, so the overall total will be maybe 6-10MB. Is this going to cause a memory problem? Is this not recommended?

I know I could have the user download them from a server on a need basis, but it would be easier if I could include them all right from the app download.


回答1:


How many images can you store in XCAssets?

Well... As per Apple on Maximum build file sizes:

Your app’s total uncompressed size must be less than 4GB

So technically you can store as many assets that can fit in this limit.
It's not going to cause memory problem because these images are stored in the app's bundle which is eventually stuff stored on disk.

It's just going to increase the app download size... for now. It will affect the app's memory once they are used/displayed.

Best example for this are games, they generally have many assets and almost always in the app's bundle itself. In some cases you would even download expansion packs that contain more assets but seldom will you see a game art download, atleast not while playing because smoothness is a key factor whether it be a game or a simple app.


Around 2,000. However, they are all very small/highly optimized at only around 3-5kB each, so the overall total will be maybe 6-10MB.

Firstly, 10MB is hardly anything to worry about but anyways the point is that if you load all 2000 images at the same time, i.e each image is loaded in a UIImageView, only then will they be loaded in app's memory.
This wouldn't matter whether you had to load the images from the app's bundle or you had to download it from a server.


How many images should you store in XCAssets?

Now that depends on you.

Consider the following before deciding:

  • Are these images likely to change?
  • Do my users need all 2000 images?
  • Do we want to maintain a list of urls for 2000 images?
  • Do we need to ensure that the images download properly?
  • Would users mind waiting a few milliseconds for an image to load?
  • If an image doesn't download, for whatever reason, then what should be an appropriate failure mechanism?

Depending on how you answer the above, you will know what path you need to take.



来源:https://stackoverflow.com/questions/50109636/how-many-images-can-should-you-store-in-xcassets-in-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!