I am building my flash card iOS app for reviewing my learning Japanese using SwiftUI language. The problem is how to storing and updating my images(>500 images). Please help me, any suggestion is appreciated, thanks for reading my post.
2 Answers
I think you're asking about how to manage 500+ images in an Xcode project. You could just add all the images to your project and load them as you would any image. You could use asset catalogs, which have the advantage that they let you store different versions of a resource for use on different devices, and only the ones needed for the device the app runs on will actually be installed on the device. See How Many Images Can/Should you Store in xcassets in Xcode? and Asset Catalog Format Reference for more information about asset catalogs. But any way you slice it, managing 500+ images is going to be cumbersome. There's probably a better way...
Managing all those images in your app isn't just a problem for you as the developer; building them into the app will also create problems for the user. Even if each image is relatively small, having hundreds of them in the app will probably make the app huge. That means it'll take a long time to install, and the app will use a lot of storage on the device. Every time you release a new version of the app, with more words, or even just to fix a few small bugs, the user will have to download all that data all over again.
Instead, you should consider building an app that can fetch the data it needs from a server. Ideally, you could apply that approach to all your app's data, not just the images. Maybe you'll organize your flash cards into sets of a few dozen, so that you can fetch a set of cards and the associated images pretty quickly, and sets that the user hasn't used for a while can be removed to free up space on the device. You'll be able to update a set of flash cards without having to update the app, and when you do update the app your users won't have to download all the data all over again.
You've said that you're a beginner, so this approach might seems very difficult. That's OK, you can start with a simpler approach and then improve as you go along. For example, you might just put all the images on a server and fetch them one at a time as you need them. Your flash card data file could contain just a dictionary with words and the URLs associated with those words. There are lots of examples of loading an image from an URL here on SO and elsewhere, so I'm not going to provide code for that, but it won't be hard to find. The earlier you start thinking about how to design your app so that it can scale as you add more and more words, the easier it will be to maintain the app later.

- 124,013
- 19
- 183
- 272
-
I agree with you - store images locally in the assets - the easiest way. Anyway the part of storing images on the aws bucket for example and load then - very easy and will be useful to practice. (It took 10 mins max if you already signed in) – Alex Jun 04 '20 at 15:26
-
That's what i'm thinking, already added 500 images in asset folder and focusing on design and logic (app flow) now. Thank you for considering solution in beginner's point view. I totally agree with you guys. – vicktor9450 Jun 04 '20 at 21:19
500 images can have a huge size. Applications that published on Appstore have size limit and Apple does not recommend to make big apps.
Store them on server and load needed images on fly. Also you will get possibility to update your images, remove add new.
If you don't have a backend, you can use something easy and free (Firebase storage for example) or with minimal code writing on AWS.
If you need to keep them on device - store them as files in the Documents or another apps folder, do not use CoreData for it (you can keep only the list of names/urls in database).
After loading image to be displayed for user, you can prefetch next bunch of images.
Use Alamofire, or SDWebImage to load images from network (I prefer last). These frameworks can do many useful things with images.
To load images:
- you can have a list of your images (just list of the names and urls) or
- you can know only path and names pattern and generate links dynamically (like https://myserver/imageXXX.png.

- 2,100
- 19
- 26
-
Thanks for suggestion but with my beginner level, could you give me an example or tutorial link please – vicktor9450 Jun 04 '20 at 14:17
-
@Alex, I will dive into Firebase because when googling my question, firebase is show on 1st place. Thank you very much. – vicktor9450 Jun 04 '20 at 14:36
-
the best url I use every day its shorturl.at/arvw6. Unfortunately I can't quick find something about it, but I'm sure that such a smart guy like you will found needed tutorials. The main - is to understand the direction. – Alex Jun 04 '20 at 14:41
-
1
-
also I recommend to try to do it with AWS bucket. Because I don't know (mostly - no) if you can get image from Firebase storage without link (just knowing image name and path). With S3 you can (As I know). – Alex Jun 04 '20 at 14:59
-
For example: with AWS: create backet, setup permissions to free read. Upload files. then just load them: https://yourbucketname.s3.amazonaws.com/filename.extension to load image you can use SDWebImage: imageView. sd_setImage(with: url, placeholderImage: placeholderImage) – Alex Jun 04 '20 at 15:21