简体   繁体   English

iPhone线程加速应用程序的启动

[英]iphone threading speed up startup of app

I have an app that must get data from the Sqlite database in order to display the first element to the User. 我有一个应用程序,必须从Sqlite数据库中获取数据才能向用户显示第一个元素。

I have created a domain object which wraps the DB access and is a thread safe singleton. 我创建了一个域对象,该对象包装了数据库访问权限,并且是线程安全的单例对象。

Is this following strategy optimal to ensure the fastest load given the iPhone's file access and memory management capabilities in threaded apps: 考虑到线程应用中iPhone的文件访问和内存管理功能,以下策略是否最佳以确保最快的负载:

1) In the AppDelegate's FinishedLaunching event the very first thing I do is create the domain singleton within a new thread. 1)在AppDelegate的FinishedLaunching事件中,我要做的第一件事是在新线程中创建域单例。 This will cause the domain object to go to Sqlite and get the data it needs without locking the UI thread. 这将导致域对象转到Sqlite并获取所需的数据,而无需锁定UI线程。

2) I then call the standard Window methods to add the View and MakeKeyAndVisible etc. 2)然后我调用标准的Window方法以添加View和MakeKeyAndVisible等。

Is there an earlier stage in the AppDelegate where I should fire off the thread that creates the Domain Object and accesses Sqlite? AppDelegate中是否有一个较早的阶段,我应该在该阶段启动创建域对象并访问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. 嘿,您可以一路回到应用程序的执行入口点,并在调用UIApplicationMain之前创建自己的线程...这太过分了。

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. applicationDidFinishLaunching是最好的选择,如果您担心快速加载,一种更好的方法是将数据缓存在plist或NSUserDefaults中,然后在数据库准备好后几百毫秒更新它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM