{"id":13428701,"url":"https://github.com/supermarin/ObjectiveRecord","last_synced_at":"2025-03-16T01:32:54.734Z","repository":{"id":3210607,"uuid":"4244828","full_name":"supermarin/ObjectiveRecord","owner":"supermarin","description":"ActiveRecord-like API for CoreData","archived":true,"fork":false,"pushed_at":"2018-08-27T10:53:58.000Z","size":3261,"stargazers_count":1292,"open_issues_count":29,"forks_count":194,"subscribers_count":61,"default_branch":"master","last_synced_at":"2024-10-20T13:10:53.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supermarin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-06T23:24:00.000Z","updated_at":"2024-10-17T01:37:54.000Z","dependencies_parsed_at":"2022-08-19T13:01:06.317Z","dependency_job_id":null,"html_url":"https://github.com/supermarin/ObjectiveRecord","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supermarin%2FObjectiveRecord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supermarin%2FObjectiveRecord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supermarin%2FObjectiveRecord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supermarin%2FObjectiveRecord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supermarin","download_url":"https://codeload.github.com/supermarin/ObjectiveRecord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814905,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:01:03.147Z","updated_at":"2025-03-16T01:32:54.431Z","avatar_url":"https://github.com/supermarin.png","language":"Objective-C","readme":"# ObjectiveRecord [![CocoaPod][pd-bdg]][pd] [![Build Status][ci-bdg]][ci]\n\n[pd-bdg]: https://img.shields.io/cocoapods/v/ObjectiveRecord.svg\n[pd]: http://cocoadocs.org/docsets/ObjectiveRecord\n[ci-bdg]: https://travis-ci.org/supermarin/ObjectiveRecord.svg\n[ci]: https://travis-ci.org/supermarin/ObjectiveRecord\n\nObjective Record is a lightweight ActiveRecord way of managing Core Data\nobjects. If you've used Ruby on Rails before, it might sound\nfamiliar.\n\nNo AppDelegate code required. It's fully tested with\n[Kiwi](https://github.com/allending/Kiwi).\n\n#### Usage\n\n1. Install with [CocoaPods](http://cocoapods.org) or clone\n2. `#import \"ObjectiveRecord.h\"` in your model or .pch file.\n\n#### Create / Save / Delete\n\n``` objc\nPerson *john = [Person create];\njohn.name = @\"John\";\n[john save];\n[john delete];\n\n[Person create:@{ \n    @\"name\" : @\"John\",\n    @\"age\" : @12, \n    @\"member\" : @NO \n}];\n```\n\n#### Finders\n\n``` objc\n// all Person entities from the database\nNSArray *people = [Person all];\n\n// Person entities with name John\nNSArray *johns = [Person where:@\"name == 'John'\"];\n\n// And of course, John Doe!\nPerson *johnDoe = [Person find:@\"name == %@ AND surname == %@\", @\"John\", @\"Doe\"];\n\n// Members over 18 from NY\nNSArray *people = [Person where:@{ \n                      @\"age\" : @18,\n                      @\"member\" : @YES,\n                      @\"state\" : @\"NY\"\n                  }];\n\n// You can even write your own NSPredicate\nNSPredicate *predicate = [NSPredicate\n    predicateWithFormat:@\"(name like[cd] %@) AND (birthday \u003e %@)\",\n            name, birthday];\nNSArray *results = [Person where:predicate];\n```\n\n#### Order and Limit\n\n``` objc\n// People by their last name ascending\nNSArray *sortedPeople = [Person allWithOrder:@\"surname\"];\n\n// People named John by their last name Z to A\nNSArray *reversedPeople = [Person where:@{@\"name\" : @\"John\"} \n                                  order:@{@\"surname\" : @\"DESC\"}];\n\n// You can use NSSortDescriptor too\nNSArray *people = [Person allWithOrder:[NSSortDescriptor sortDescriptorWithKey:@\"name\" ascending:YES]];\n\n// And multiple orderings with any of the above\nNSArray *morePeople = [Person allWithOrder:@\"surname ASC, name DESC\"];\n\n// Just the first 5 people named John sorted by last name\nNSArray *fivePeople = [Person where:@\"name == 'John'\"\n                              order:@{@\"surname\" : @\"ASC\"}\n                              limit:@(5)];\n```\n\n#### Aggregation\n\n``` objc\n// count all Person entities\nNSUInteger personCount = [Person count];\n\n// count people named John\nNSUInteger johnCount = [Person countWhere:@\"name == 'John'\"];\n```\n\n#### Custom ManagedObjectContext\n\n``` objc\nNSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];\nnewContext.persistentStoreCoordinator = [[CoreDataManager instance] persistentStoreCoordinator];\n\nPerson *john = [Person createInContext:newContext];\nPerson *john = [Person find:@\"name == 'John'\" inContext:newContext];\nNSArray *people = [Person allInContext:newContext];\n```\n\n#### Custom CoreData model or .sqlite database\nIf you've added the Core Data manually, you can change the custom model and database name on CoreDataManager\n``` objc\n[CoreDataManager sharedManager].modelName = @\"MyModelName\";\n[CoreDataManager sharedManager].databaseName = @\"custom_database_name\";\n```\n\n#### Examples\n\n``` objc\n// find\n[[Person all] each:^(Person *person) {\n    person.member = @NO;\n}];\n\nfor(Person *person in [Person all]) {\n    person.member = @YES;\n}\n\n// create / save\nPerson *john = [Person create];\njohn.name = @\"John\";\njohn.surname = @\"Wayne\";\n[john save];\n\n// find / delete\n[[Person where: @{ @\"member\" : @NO }] each:^(Person *person) {\n    [person delete];\n}];\n```\n#### Mapping\n\nThe most of the time, your JSON web service returns keys like `first_name`, `last_name`, etc. \u003cbr/\u003e\nYour ObjC implementation has camelCased properties - `firstName`, `lastName`.\u003cbr/\u003e\n\nSince v1.2, camel case is supported automatically - you don't have to do anything! Otherwise, if you have more complex mapping, here's how you do it:\n\n``` objc\n// just override +mappings in your NSManagedObject subclass\n// this method is called just once, so you don't have to do any caching / singletons\n@implementation Person\n\n+ (NSDictionary *)mappings {\n  return @{ \n      @\"id\": @\"remoteID\",\n      @\"mmbr\": @\"isMember\",\n      // you can also map relationships, and initialize your graph from a single line\n      @\"employees\": @{\n          @\"class\": [Person class]\n      },\n      @\"cars\": @{\n          @\"key\": @\"vehicles\",\n          @\"class\": [Vehicle class]\n      }\n  };\n  // first_name =\u003e firstName is automatically handled\n}\n\n@end\n```\n\n#### Testing\n\nObjectiveRecord supports CoreData's in-memory store. In any place, before your tests start running, it's enough to call\n``` objc\n[[CoreDataManager sharedManager] useInMemoryStore];\n```\n\n#### Roadmap\n\n- NSIncrementalStore support\n\n## License\n\nObjectiveRecord is available under the MIT license. See the LICENSE file\nfor more information.\n","funding_links":[],"categories":["Core Data","Objective-C","Objective-C  Stars 1000以内排名整理","etc"],"sub_categories":["Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupermarin%2FObjectiveRecord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupermarin%2FObjectiveRecord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupermarin%2FObjectiveRecord/lists"}