Hi, I am designing a simple task manager for a household in SwiftUI. I would like the app to synchronise the content data across the devices of the various users part of the household. To me, this seems like a simple enough process potentially. Which approach is best suitable with the SwiftUI framework?
The data model of the app is very simple at the moment; essentially a collection of tasks that each feature a title, description and assignment to a user. Running the app locally, without synchronisation implemented yet, allows me to make use of the SwiftUI's framework declarative programming and elegant design.
I realise that to implement synchronisation with other users' devices unavoidably means I need to implement code and adapt existing code. For years, I have browsed articles and tutorials on data sharing in iOS apps. Options I have explored are Core Data, CloudKit, manual API fetching from server and third-party options like Realm. The underlying, unnamed issue seems to be that SwiftUI is still young and data frameworks don't yet offer an elegant integration.
I am looking for an approach that integrates best with SwiftUI's elegance and framework with respect to data propagation (ObservableObjects and such).
Core Data provides a way to store data persistently and is fairly integrateable with SwiftUI, given it's Apple's own framework; even @FetchRequests are available. However, it does seem quite old (for example in use and interpretation of nil values of object members) and uses classes instead of structs. I have read quite some tutorials on using Core Data with SwiftUI, but these range from being very unscalable (e.g. writing the full CRUD, repetitive operations within View layers) to conversion between structs and classes and apparent instability w.r.t. synchronisation (after a successful Core Data save, also adding a struct to some observed @Published list to keep using SwiftUI's data propagation mechanisms).
Core Data itself does not necessarily offer sharing between devices, it is merely a storage method. It does provide an interface with CloudKit, but this only synchronises its state within one user's iCloud (e.g. NSPersistentCloudKitContainer does not support a shared scope). - https://developer.apple.com/forums/thread/649630 This seems to imply CoreData itself cannot provide the functionality I am looking for.
CloudKit itself is also provided by Apple and offers features such as shared records, which does allow sharing between users. However, I cannot find a good documentation or explanation on how to combine SwiftUI and CloudKit to maintain a synchronised state between users.
Alternatively, using Codable structs would allow to convert server responses to local data or send local data to a server. I have also created CRUD API's previously, so implementing the server side should be no problem. However, with the task of merging conflicting edits and notifying users' devices I have no experience, so this seems a little too complex to do right.
Then lastly, Realm also offers a remote database management system, but the implementation in SwiftUI seems hacky at best, with a lot of overhead code.
Concluding, what is in your experience and opinion the best/most elegant or/most viable way, for a simple SwiftUI app, to implement data synchronisation for a simple data model across multiple users' devices?
Or, is this not available at this time? (A positive answer here would be equally informative :-)
I would love to hear your ideas,
Kind regards, Isaiah
Post
Replies
Boosts
Views
Activity
I would like to use the MediaPlayer in Swift 5 to have a user select a song for use in my app.This should be possible using MPMediaPicker using this official Apple documentation.However, it seems this documentation is incomplete.If the user does not have the Apple Music app installed, then upon presentation of MPMediaPickerController, they are presented with the error alert "Internal Error", "The requested app extension could not be found" (image). This is undesirable, uninformative to the user and seemingly unpreventable.This is also irregardless of having correctly set the NSAppleMusicUsageDescription key in Info.plist and having the appropriate (authorized) MPMediaLibraryAuthorizationStatus.The necessity of having the Apple Music app installed is mentioned nowhere in Apple's documentation, which is lacking.Secondly, there appears to be no way (that I could find on the Internet) to then manually check beforehand if the Apple Music app is installed._____How can my app determine if the Apple Music app is installed, in order to prevent presenting a MPMediaPickerController if there is no music app installed and so prevent the uninformative and undetectable error displayed otherwise?Kind regards,Isaiah