Best practice for storing and updating images in Xcode project - ios

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.

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.

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.

Related

Large amounts of images in Firebase

I am currently developing an iOS App for a photographer. The main attraction of the App is going to be a gallery of their work, so about 300MB of Images.
My plan until now was to include lower resolution versions of the Images on the App itself and have the full resolution Images pulled from a FirebaseDatabase to replace the low-res versions.
Now I am doubting myself though, since pulling 300MB worth of Images from Firebase for every user seems like it would get rather costly. Would it be a better bet for me to just accept the bigger download and include all of the Images in the App? Considering that would also save the users time and give them a smoother experience it seems like the better option. But I am not sure if there are issues with this that I am not aware of.
How do people usually deal with this sort of a thing?

Sharing data between apps on iOS

I have several small apps that share common data (images, sounds files, etc). This data bloats the size of each app. When the user installs 2 or more of these apps that will bloat the device space with duplicate data. Is there a way that I can share this data between my apps so that each app doesn't duplicate this data within its bundle?
You can have a common file space between apps by using app groups. An example of how to use them can be found here: Sharing data in between apps in IOS
You can use this as part of a solve for not duplicating the data in every bundle. One way might be to have the data hosted on a server somewhere and when the app is installed you can check the App Group for the common data, if it is not there, you can download it and store it there. Then the next app that is installed will have the data already available. This should help avoid having to include it in every small app.
You can set up the code to check the shared location and download the data in a framework and share it between all your apps making it a bit easier to maintain. If you do not already have a content management system then you could google for a few that have iOS support. There are many out there. You would then host the shared data there. This would give you the ability to update the data for each app while they are in the field which could be a time saver. If these apps are very small though, this may be overkill.
No, this is not currently possible. Ideally, this kind of resource-sharing would require creating a common framework bundle that would have to
be submitted separately to the App Store as a third-party framework, so that even if only one of your apps is present on the
device, it would be able to load the appropriate resources and function properly.
Apple currently only allows third-party frameworks embedded within the app bundle.
Even if two of your apps use the same exact version of your framework, they have to embed it separately.

Best storage and organisation approach IOS app

I'm building an IOS app (native) where a number of football teams are presented on the screen for the user to select a favourite. Whats the best approach for storing / building these team objects in the app.
One possibility would be to collect all the teams from an API and store them in some kind of IOS storage / database component, however the teams will rarely change so it seems over kill. Another option is just to hard code it by creating each team in something like the app delegate or storing them in a plist.
Secondly each team will have images associated with them e.g. badge, players etc. Whats the best way to organise these image assets. From what I can see images can be grouped into folders in images.xassets however those folders are ignored when calling the image from code.
[UIImage imageNamed:#"badge"];
Which would be a problem since each team would have an image named badge. Should I prepend the image name with the corresponding team name or is there a better way to link and organise these assets to a given team.
I would look into sqlite data base with CoreData interface. You can organize perfectly well what you need. It also allows for image storage. If you've never worked with it, it migth be difficult at the beginning, but after the learning curve you'll find it really useful.

Share Files between Apps on the same iPad (Without iCloud)

I have two iPad apps, one which downloads data from a server and stores it on the iPad and another one (the main app) which uses the data later.
(It would make sense to combine the two but it's a client requirement)
But I see no way to share the data between the two apps.
I have heard there are ways to do it using:
Custom URL Schemes
Document Support on iPad Devices
UIPasteboard
But I cannot find any thing explaining how to use any of these effectively.
Can anyone point me in the right direction.
Just to clarify:
It is an iPad only app
Both apps will not run at the same time
Basically I need to access the documents or caches folder of one app from another
Using iCloud or any other third part service is not possible
It would be great if I could make the downloader app into a sort of configuration page for the main app (if it is even possible)
So keeping these in mind which one would be the most suitable?
This link at github may be useful... Looks like someone has already made a file manager, using these elements you may be able to do what you are looking for. But as far as I know, your app is extremely sandboxed and does not really interact with other apps/the file system very much at all (Apple is very limiting that way)
EDIT
this post seems to have the explanations of local data sharing methods you were looking for. None of the methods in this post requires any connectivity, just a device and 2 apps :) Good luck!

Solutions for selecting and attaching images to models?

I'm trying to be lazy and would rather find an existing gem, plugin, etc. instead of writing my own implementation. The use case seems to me general enough that there may be something out there, but I can't find anything.
We're using Ruby on Rails and carrierwave to have users upload images that attach to so-called activities (which need to be curated several times a day). It turns out that users often (re-)use the same images for different activities. Instead of making the users upload the same image again all the time, I want to present them with a small gallery of images, and let them pick one to be used (or let them upload if they really want to, of course).
Is there something out there that would help me ?

Resources