I have an app that must get data from the Sqlite database in order to display the first element to the User.
I have created a domain object which wraps the DB access and is a thread safe singleton.
Is this fol开发者_JS百科lowing strategy optimal to ensure the fastest load given the iPhone's file access and memory management capabilities in threaded apps:
1) In the AppDelegate's FinishedLaunching event the very first thing I do is create the domain singleton within a new thread. This will cause the domain object to go to Sqlite and get the data it needs without locking the UI thread.
2) I then call the standard Window methods to add the View and MakeKeyAndVisible etc.
Is there an earlier stage in the AppDelegate where I should fire off the thread that creates the Domain Object and accesses Sqlite?
Heh, you can go all the way back to the app's execution entry point and create your own thread before invoking UIApplicationMain... that's overkill.
applicationDidFinishLaunching is the best place to do it, if you're worried about fast loading a better approach would be to cache the data in your plist or NSUserDefaults and then update it a couple hundred millisecs later when the DB is ready.
精彩评论