sqlite and threading with iPhone SDK

后端 未结 4 546
粉色の甜心
粉色の甜心 2020-12-10 21:37

I have an iPhone app that is using sqlite 3.6 (not with FMDB) to store and load data. I load the database when the app loads and uses the same database connection through th

4条回答
  •  不知归路
    2020-12-10 21:57

    This is all explained in the Core Data Programming Guide in the section for Concurrency.

    The pattern recommended for concurrent programming with Core Data is thread confinement.

    You should give each thread its own entirely private managed object context and keep their associated object graphs separated on a per-thread basis.

    There are two possible ways to adopt the pattern:

    Create a separate managed object context for each thread and share a single persistent store coordinator. This is the typically-recommended approach.

    Create a separate managed object context and persistent store coordinator for each thread. This approach provides for greater concurrency at the expense of greater complexity (particularly if you need to communicate changes between different contexts) and increased memory usage.

提交回复
热议问题