Magical record (based on coredata) for ios data persistence)

Source: Internet
Author: User

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


Related Article

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.