I’m trying to create a singleton service/ manager for managing user accounts for an Objective-C iOS app. It will be responsible for:
- Adding the user to my CloudKit database if (s)he is new
- Getting the users metadata from the CloudKit database
- Verifying user-inputted emails with a 3rd party verification API
- Adding the email to the users record in the CloudKit database
- Sending the email to MailChimp
And answering questions from my app, such as:
- Is the current user logged into iCloud
- Is this a new user
- Has this user added their email
What I’m curious about is the general architecture of this service with regards to its initialization, etc. I would like to preload as much information as possible by initializing it in the AppDelegate, but other places in my code might also call into it before its done initializing (adding the user to CloudKit etc.). If so, these will need to wait. If there is an error during initialization, any subsequent calls to any method of this service will attempt to initialize and return the appropriate error if there is one.
I can’t recall to have ever seen any code examples or guides on how to create a large-scale service such as this, how to handle its initialization, errors, etc. Any advice would be appreciated.
In advance, thank you.