Search code examples
iosjsonfmdb

FMDB block my UI


Fmdb in iOS, I have a task to convert 100 JSON string to my model from network and then represent them on the UITableViewCell, because I have 3 button to change the data on the UITableView , so I fmdb the data to local, when I change the data it first check to read the local data, and then request newest data to reload UITableView and save to database. All 3 changes have the same logic. Because 100 data to store I choose to asynchronous dispatch the for statement, then the problem is when the model inserts in to table it stuck my UI a little bit. My table has 10+ columns , is there any possibility just because too much columns cause insert assume too much time?


Solution

  • According to FMDB documentation, it's better to use FMDatabaseQueue for your case.

    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.

    Here's the reference.