Giter Site home page Giter Site logo

logen525 / coredataenvir Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dehengxu/coredataenvir

0.0 2.0 0.0 802 KB

A CoreData Envirement wrapper, use CoreData in convenient way. It has been used in my work.

Home Page: http://xudeheng.github.io/CoreDataEnvir

License: MIT License

coredataenvir's Introduction

CoreDataEnvir (2011-05-25)

A CoreData Envirement wrapper, use CoreData in convient way. You can use it in concurrency,run seperate CoreDataEnvir instance on one thread.

##First step: //Register your data base file name [CoreDataEnvir registDatabaseFileName:@"db.sqlite"]; //Register your model file name(no extension) [CoreDataEnvir registModelFileName:@"SampleModel"];

##On main thread:

#Insert item: Team *team = [Team insertItem]; or [Team insertItemWith:^(Team *item) { item.name = [NSString stringWithFormat:@"Nicholas"]; }];

[team save];//Save to data base on main thread.
or
[team remove];//Remove from data on main thread.

#Fetch one item: Team *team = (Team *)[Team lastItemWith:[NSPredicate predicateWithFormat:@"name==nicholas"]];

#Fetch all items: NSArray *allItems = [Team items];

##If you want to run on other threads, follow this:

This method ([CoreDataEnvir instance]) will automatically creating new instance for non-main thread and uniq instance for main thread.

dispatch_async(q2, ^{
	CoreDataEnvir *db = [CoreDataEnvir instance];
	for (int i = 0; i < 500; i++) {
		Team *team = (Team *)[Team lastItemWith:db predicate:[NSPredicate predicateWithFormat:@"name==9"]];
		if (team) {
			[team removeFrom:db];//Remove from db.
		}else {
			[Team insertItemWith:db fillData:^(Team *item) {
				item.name = [NSString stringWithFormat:@"9"];
			}];
			
		}
		[team saveTo:db];//Save db.
	}
});

##If your are newcomer to CoreData, please obey the rules below: If you wanna keep you NSManagedObject objects, you shouldn't release you CoreDataEnvir object or it will be fault. So if you operate data base in multiple threads, make sure your NSManagedObject object reference fetched from [CoreDataEnvir mainInstance] or [CoreDataEnvir backgroundInstance] which never be released until application exist.

coredataenvir's People

Contributors

dehengxu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.