{"id":18554661,"url":"https://github.com/realmteam/coredatahelper","last_synced_at":"2025-12-12T06:01:38.957Z","repository":{"id":56906683,"uuid":"54861588","full_name":"RealmTeam/CoreDataHelper","owner":"RealmTeam","description":"CoreDataHelper is a tiny Swift Framework that helps you to easily manage CoreData objects in the main context.","archived":false,"fork":false,"pushed_at":"2017-03-19T11:28:58.000Z","size":68,"stargazers_count":14,"open_issues_count":1,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T06:06:38.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","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/RealmTeam.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-03-28T03:05:27.000Z","updated_at":"2022-12-07T02:19:10.000Z","dependencies_parsed_at":"2022-08-21T02:20:58.983Z","dependency_job_id":null,"html_url":"https://github.com/RealmTeam/CoreDataHelper","commit_stats":null,"previous_names":["lobodart/coredatahelper"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealmTeam%2FCoreDataHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealmTeam%2FCoreDataHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealmTeam%2FCoreDataHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealmTeam%2FCoreDataHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RealmTeam","download_url":"https://codeload.github.com/RealmTeam/CoreDataHelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129847,"owners_count":21052648,"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-11-06T21:23:17.667Z","updated_at":"2025-12-12T06:01:33.919Z","avatar_url":"https://github.com/RealmTeam.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoreDataHelper\n\nCoreDataHelper is a tiny Swift Framework that helps you to easily manage CoreData objects in the main context.\n\n## Installation\n\nTo install this, simply add the `.xcodeproj` to your project, and do not forget to link the `.framework`.\n\n\nIf you're using cocoapods, just add `pod 'CoreDataHelper'` into your `Podfile` file.\n\n\nWhenever you want to use it in your code, simply type :\n```swift\nimport CoreDataHelper\n```\n\n## Getting started\n\nTo start with CoreDataHelper, it is pretty simple. Just go to your `AppDelegate.swift` file and add the following code :\n```swift\nfunc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -\u003e Bool {\n\n  CDHelper.initializeWithMainContext(self.managedObjectContext)\n  // OR\n  CDHelper.initializeWithMainContext(self.persistentContainer.viewContext) // New XCode 8/Swift 3 template\n  \n  return true\n}\n```\n\nNote that your project must use CoreData.\n\n## Create your first entity class\n\nLet's create an entity named `User` which contains 4 properties :\n- first_name (String)\n- last_name (String)\n- email (String)\n- age (Integer)\n\nOnce you created the class `User` which inherit of `NSManagedObject`, just add the `CDHelperEntity` protocol like that :\n```swift\nclass User: NSManagedObject, CDHelperEntity {\n    \n  static var entityName: String! { return \"User\" } // Required\n    \n  @NSManaged var first_name: String?\n  @NSManaged var age: NSNumber?\n  @NSManaged var email: String?\n  @NSManaged var last_name: String?\n}\n```\n\nYou just need to add the `entityName` variable to be conform with the `CDHelperEntity` protocol and that's it ! You're ready to use all the features of _CoreDataHelper_ !\n\n## Play with your entity\n\n### Create a new entity\n\nThere are two ways to create a new entity.\nFirst, you can create an empty entity and fill it after :\n```swift\nlet user: User = User.new()\nuser.first_name = \"John\"\nuser.last_name = \"Doe\"\nuser.email = \"john.doe@foobar.com\"\nuser.age = 42\n```\n\nYou can also create an entity using a data dictionary :\n```swift\nlet userData: [String: Any?] = [\n  \"first_name\": \"John\",\n  \"last_name\": \"Doe\",\n  \"email\": \"john.doe@foobar.com\",\n  \"age\": 42,\n]\n\nlet user: User = User.new(userData)\n```\n\n### Save your entity\nTo save your entity, simply use the `.save()` method like that :\n```swift\nlet user: User = User.new()\n// ...\nuser.save()\n```\n\n### Delete your entity\nIf you don't need your entity anymore, you can use the `.destroy()` method :\n```swift\nlet user: User = User.new()\n// ...\nuser.save()\n\n// ... Ok, let's admit you want to delete your user\nuser.destroy()\n```\n\n### Retrieve your entities\nThere are different ways to retrieve your entities.\n\n#### Synchronously\n##### findAll()\n- Basic use\n```swift\nlet users: [User] = User.findAll()\n```\n- Using sort descriptor(s)\n```swift\nlet users: [User] = User.findAll(usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)])\n```\n\n##### findOne()\n```swift\nlet user: User? = User.findOne(\"first_name=\\\"John\\\"\")\n```\n\n##### find()\n- Basic use\n```swift\nlet users: [User] = User.find(\"first_name=\\\"John\\\"\")\n```\n- Using sort descriptor(s)\n```swift\nlet users: [User] = User.find(\"first_name=\\\"John\\\"\", usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)])\n```\n- Using fetch limit\n```swift\nlet users: [User] = User.find(\"first_name=\\\"John\\\"\", limit: 5)\n```\n- Using both\n```swift\nlet users: [User] = User.find(\"first_name=\\\"John\\\"\", usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)], limit: 5)\n```\n\n#### Asynchronously\n##### asynchronouslyFindAll()\n- Basic use\n```swift\nUser.asynchronouslyFindAll { (results: [User]) -\u003e Void in\n  // ...\n}\n```\n- Using sort descriptor(s)\n```swift\nUser.asynchronouslyFindAll(usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)]) { (results: [User]) -\u003e Void in\n  // ...\n}\n```\n\n##### asynchronouslyFindOne()\n```swift\nUser.asynchronouslyFindOne(\"first_name=\\\"John\\\"\") { (user: User?) -\u003e Void in\n  // ...\n}\n```\n\n##### asynchronouslyFind()\n- Basic use\n```swift\nUser.asynchronouslyFind(\"first_name=\\\"John\\\"\") { (user: [User]) -\u003e Void in\n  // ...\n}\n```\n- Using sort descriptor(s)\n```swift\nUser.asynchronouslyFind(\"first_name=\\\"John\\\"\", usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)]) { (user: [User]) -\u003e Void in\n  // ...\n}\n```\n- Using fetch limit\n```swift\nUser.asynchronouslyFind(\"first_name=\\\"John\\\"\", limit: 5) { (user: [User]) -\u003e Void in\n  // ...\n}\n```\n- Using both\n```swift\nUser.asynchronouslyFind(\"first_name=\\\"John\\\"\", usingSortDescriptors: [NSSortDescriptor(key: \"first_name\", ascending: true)], limit: 5) { (user: [User]) -\u003e Void in\n  // ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealmteam%2Fcoredatahelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealmteam%2Fcoredatahelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealmteam%2Fcoredatahelper/lists"}