Magical record (based on coredata) for ios data persistence)
After seeing magical record, I tried it and found it useful,
Magic Record is an open-source class library written by Saul Mora to make Core Data easier to use. The development of this library is inspired by the active record mode in Ruby on Rails (Web Application Framework ).
Installation steps:
Http://blog.csdn.net/kuizhang1/article/details/21200367
Specific use:
/* Add record */
Person * person = [PersonMR_createEntity];
Person. firstname = @ "Frank ";
Person. lastname = @ "Zhang ";
Person. age = @ 26;
[[NSManagedObjectContextMR_defaultContext] MR_saveToPersistentStoreAndWait];
//
/// * Query */
// NSArray * persons = [Person MR_findAll];
// NSLog (@ "% d", [persons count]);
// For (Person * persontemp in persons ){
// NSLog (@ "firstname: % @ ---- lasename: % @ ---- age: % @", persontemp. firstname, persontemp. lastname, persontemp. age );
//}
//// Search for all persons in the database.
// NSArray * persons = [Person MR_findAll];
//
//// Search for all persons and sort them by first name.
// NSArray * personsSorted = [Person MR_findAllSortedBy: @ "firstname" ascending: YES];
//
//// Query all the Person records whose age attribute is 25.
// NSArray * personsAgeEuqals25 = [Person MR_findByAttribute: @ "age" withValue: [NSNumber numberWithInt: 25];
//
//// Search for the first record in the database
// Person * person = [Person MR_findFirst];
/* Change */
// NSArray * wellperson = [Person MR_findByAttribute: @ "lastname" withValue: @ "Zhang" andOrderBy: @ "age" ascending: YES];
// For (Person * persontemp in wellperson ){
// Persontemp. lastname = @ "kun ";
//}
// [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
/// * Query */
// NSArray * persons = [Person MR_findAll];
// NSLog (@ "% d", [persons count]);
// For (Person * persontemp in persons ){
// NSLog (@ "firstname: % @ ---- lasename: % @ ---- age: % @", persontemp. firstname, persontemp. lastname, persontemp. age );
//}
/* Delete */
// Delete all users in the database
// [Person MR_truncateAll];
// [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
// Delete a specific person based on the Condition
NSArray * personsdelete = [PersonMR_findByAttribute: @ "lastname" withValue: @ "Zhang" andOrderBy: @ "age" ascending: YES];
NSLog (@ "% d", [personsdeletecount]);
For (Person * personin personsdelete ){
[Person MR_deleteEntity];
}
[[NSManagedObjectContextMR_defaultContext] MR_saveToPersistentStoreAndWait];
The emergence of Magical Record relieves this problem to a certain extent and lowers the threshold for using Core Data, which is more concise and efficient than using coredata directly.
Magical record third-party download: https://github.com/magicalpanda/MagicalRecord