Hi everyone. I have a question. I am a beginner and I am currently developing a webshop iOS application in Swift. Data is pulled from the Magento backend, via GraphQL and the Apollo client. I need the application to download all data about products and prices while it is online, but to be able to work later in offline mode as well. So when he returns to the online mode, to withdraw all changes and if there are any, to write them in Core Data. Is Core Data a good choice for such a thing? Or can you suggest something else for that thing? Thanks
Welcome to the community!
What do you mean “webshop iOS app?”
Check in what Apollo has for options, for caching data, I think it does this automatically for you
It sounds like you’re looking for a solution to handle data synchronization between your online and offline states in your iOS application. Although Core Data is a good choice for many applications, you might also want to consider using Realm for this purpose.
Realm is a popular, powerful, and easy-to-use mobile database that can be a great alternative to Core Data. It offers robust support for offline-first applications like your webshop app, and it can simplify data management and synchronization.
Here are some advantages of using Realm in your scenario:
- Easy to use: Realm’s API is straightforward and easy to learn, especially for beginners. It provides a clean, object-oriented interface that can help you get up and running quickly.
- Cross-platform: Realm supports multiple platforms, including iOS, Android, and React Native. This can be advantageous if you plan to expand your application to other platforms in the future.
- Real-time synchronization: Realm offers the Realm Sync feature, which enables real-time, bidirectional data synchronization between your mobile app and backend server. When your app is online, changes are synced automatically. When offline, Realm stores changes locally, and the sync resumes once the device is back online.
- Performance: Realm is known for its performance and efficiency, especially when handling large datasets.
- Flexible schema: Realm allows you to define your data model using Swift classes, and it supports flexible schema updates, making it easier to evolve your data model as your application grows.
To implement Realm in your application, follow these steps:
- Install Realm: Add the RealmSwift package to your project using Swift Package Manager, CocoaPods, or Carthage. You can google who to install Realm to learn more.
Define your data model: Create Swift classes that inherit from
Objectand define your properties. Use the
@Persistedproperty wrapper for your fields.
Set up your Realm instance: Instantiate a
Realmobject, which represents your local database.
Perform CRUD operations: Use the
Realminstance to add, update, delete, and query objects.
- Implement Realm Sync (optional): If you want to use the synchronization features, you will need to set up the Realm Object Server and configure your app to use it.
In conclusion, Realm can be a great choice for your webshop iOS application, particularly if you require seamless data synchronization between online and offline states. Its ease of use, performance, and flexibility make it a strong contender for this kind of project.
Thank you mikaelcaron for your answer, I will read the whole Apollo docs
Thanks for such a comprehensive answer. Yes, that’s exactly what I need. I did some research and compared Core Data and Realm solutions. Both have their advantages, and I don’t think I’ll go wrong using either one. It was only important for me to know if it can be used for what I needed.
Honestly, Realm is easy to use, but I would still avoid a 3rd party solution at this point. After all, Core Data is Apple’s framework. Although I haven’t decided anything yet. Thanks again for your help