A chance to see the magical record, and tried it, and found it very useful,
The Magic record is an open-source class library written by Saul Mora to make core data easy to use. This library was developed from the active record mode in Ruby on Rails (WEB application framework)
Specific 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];
//
// /* Enquiry */
Nsarray*persons = [Person Mr_findall];
NSLog (@ "%d", [persons Count]);
For (person*persontemp in persons) {
NSLog (@ "firstname:%@----lasename:%@----age:%@", persontemp.firstname,persontemp.lastname,persontemp.age);
// }
// // find all of the databases Person .
Nsarray *persons = [person Mr_findall];
//
// // Find all the Person and follow First name sort.
Nsarray *personssorted = [Person mr_findallsortedby:@ "FirstName" Ascending:yes];
//
// // Find All Age property is - of the Person Records.
Nsarray *PERSONSAGEEUQALS25 = [person mr_findbyattribute:@ ' age ' withvalue:[nsnumber numberwithint:25]];
//
// // find the first record in a 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];
// /* Enquiry */
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 people in database
[Person Mr_truncateall];
[[Nsmanagedobjectcontext Mr_defaultcontext] mr_savetopersistentstoreandwait];
// Delete a specific person according to the conditions
nsarray *personsdelete = [personmr_findbyattribute: @ "LastName"withvalue:@ "Zhang" Andorderby:@ "age"ascending:YES];
NSLog(@ "%d", [personsdeleteCount]);
for ( person *person in personsdelete) {
[ person mr_deleteentity];
}
[[nsmanagedobjectcontextmr_defaultcontext]mr_ Savetopersistentstoreandwait];
The advent of the magical record alleviates this problem to some extent, reducing the use threshold of core data, which is simpler and more efficient than using coredata directly
Magical record third-party downloads: Https://github.com/magicalpanda/MagicalRecord
iOS Data persistence magical record (based on CoreData)