Ream – (objc) write transaction reduction scheme

Time:2020-1-31

Ream – (objc) write transaction reduction scheme

Address: Realm–

There are two ways to write transactions officially provided by realm:

A[realm beginWriteTransaction];
// ...
[realm commitWriteTransaction];
B
[realm transactionWithBlock:^{
     //...
}];

Because realm forces thread safety, realm objects are not suitable to hold. Therefore, the write transaction of realm is oriented to realm programming, not to rlmobject programming. In other words, the process trace of the realm facing the past has not been eliminated. The realm pursuing speed is implemented by C + +. Realm chose speed and gave up some convenience.

This coding method is what we expect [object committransaction: ^ (object){
    object.key = value;
}];

The common encapsulation strategies are around ab. The problem around form a encapsulation is that the code loss is large, the scope is not intuitive, and cannot return in the middle. The problem of form B encapsulation is that the code loss of boasting closure passing value is large, debugging the original scope wastes time, and cannot return.

The best way to code is one line

{
    @realm_writing; /// Begin commit
    object.key = value;
} /// Commit when leava current scope.

The best way to write this method is to use the destructor of C + +. If you use C + +, all. M files will be modified to. Mm. The final choice is to use attribute.