ios核心数据如何实现sql事务函数? [英] ios core data how to implement the sql transaction function?
问题描述
喜欢标题。我使用核心数据插入项目,我插入100项,它太慢。如何提高插入速度?核心数据有交易功能?
您正在寻找的是在Core Data中 save
所有100个对象已经被插入,而不是在每个插入之后。
当对象被插入到核心数据中时,它们只存在于内存中。要将新对象保存到光盘中,您应该保存所有更改(插入,更新和删除),并将它们一起写入光盘。
如果您查看 -insertObject 的文档(下面)你可以读取插入一个对象只注册要保存更改时插入的对象。
insertObject:
在下次保存更改时注册要插入接收器持久存储的对象。 p>
- (void)insertObject:(NSManagedObject *)object
参数
b
托管对象。
进一步查看 -save的文档: (下面),您将确保(尝试)保存所有未保存的更改,(在您的情况下所有100个插入的项目)。
save:
尝试将已保存的更改提交到其持久存储库。
- (BOOL)save:(NSError **)error
参数
一个
NSError
对象。您不需要创建NSError
对象。如果您通过NULL
,保存操作将在第一个失败后中止。
返回值<
是
如果保存成功,否则NO
。
like title. I use core data to insert item, i insert 100 items , it`s too slow. How to up the insert speed? Core Data whicher has transaction funcation?
What you are looking for is to save
in Core Data after all 100 objects have been inserted as opposed to after each insert.
When objects are inserted into Core Data they are only present in memory. To persist your new objects to disc you should save which will take all changes (inserts, updates and deletes) and write them to disc together.
If you look at the documentation for -insertObject (below) you can read that inserting an object only registers the object for being inserted when changes are saved.
insertObject:
Registers an object to be inserted in the receiver’s persistent store the next time changes are saved.
- (void)insertObject:(NSManagedObject *)object
Parameters
object
A managed object.
By further looking at the documentation for -save: (below) you will se that it will (attempt to) save all the unsaved changed, in your case all 100 inserted items.
save:
Attempts to commit unsaved changes to registered objects to their persistent store.
- (BOOL)save:(NSError **)error
Parameters
error
A pointer to an
NSError
object. You do not need to create anNSError
object. The save operation aborts after the first failure if you passNULL
.Return Value
YES
if the save succeeds, otherwiseNO
.
这篇关于ios核心数据如何实现sql事务函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!