FMDB 阻止我的 UI

FMDB block my UI

Fmdb in iOS,我的任务是将 100 个 JSON 字符串从网络转换为我的模型,然后在 UITableViewCell 上表示它们,因为我有 3 个按钮更改 UITableView 上的数据,所以我将数据 fmdb 到本地,当我更改数据时它首先检查读取本地数据,然后请求最新数据重新加载 UITableView 并保存到数据库。所有 3 个更改具有相同的逻辑。因为要存储 100 个数据我选择异步调度 for 语句,那么问题是当模型插入到 table 时它卡住了我的 UI 一点点。我的table有10+列,有没有可能因为列太多导致insert assume太多时间?

根据 FMDB 文档,您的情况最好使用 FMDatabaseQueue

To perform queries and updates on multiple threads, you’ll want to use FMDatabaseQueue.

Using a single instance of FMDatabase from multiple threads at once is a bad idea. It has always been OK to make a FMDatabase object per thread. Just don’t share a single instance across threads, and definitely not across multiple threads at the same time.

Instead, use FMDatabaseQueue.

这是reference