iOS Data persistence magical record (based on CoreData)

Source: Internet
Author: User
Tags ruby on rails

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.