Question

I'm wondering if I should be relying less on my projects' App Delegate to setup my app - or should this sort of code belong to a singleton class part of the model?

For example -let's say, before my user gets to the first view - I need the app to download some data from a server and I need to preform a few checks and create a BaseDataStore type of class to store the stuff the app downloads. All this before my app starts.

Putting all this code in the applicationDidFinishLaunchingWithOptions seems like the right thing to do - as this is what gets called once the app has launched. My question: Is this the right place to put it? Or do I create my own class for this sort of thing?

Was it helpful?

Solution

In short: YES, you need to create your own classes.

To put all code in the AppDelegate and ViewController classes is a popular habit in iOS. iOS apps tend to have small (auto-generated) model classes, which are then managed from the ViewControllers or the AppDelegate. Which is the fastest way to create a fart-app and the like.

In case you're building anything bigger then a fart-app, I suggest to take a different approach: A manager class could be in change of your model (setting it up, saving, etc). The AppDelegate then calls into the model manager when needed. Also, the application code generally improves when the "application logic" is placed in the model classes. To accomodate model changes (and regenerating the model classes), the auto-generated ManagedObjects should then be extended via categories containing your "application logic".

OTHER TIPS

For simple project loading data from network your process should be :

  1. Create a custom LoadingViewController
  2. Show it from the AppDelegate applicationDidFinishLaunchingWithOptions
  3. Get the data with an entity manager
  4. With a callback (delegate pattern should be nice) launch the first viewcontroller according to your data

The first 2 steps are for showing the app data is loading to the user (if you don't do that you'll have the Default.png showing a long time). If the first ViewController data can be refreshed you can directly load it, show cached data first and launch the refresh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top