{"id":16482765,"url":"https://github.com/shaps80/populate","last_synced_at":"2025-02-28T19:42:55.276Z","repository":{"id":62451009,"uuid":"58396538","full_name":"shaps80/Populate","owner":"shaps80","description":"Data providers for populating your data views.","archived":false,"fork":false,"pushed_at":"2016-07-14T16:01:05.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-11T18:02:54.164Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/shaps80.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-05-09T17:51:53.000Z","updated_at":"2021-12-15T07:08:11.000Z","dependencies_parsed_at":"2022-11-01T23:33:11.210Z","dependency_job_id":null,"html_url":"https://github.com/shaps80/Populate","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FPopulate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FPopulate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FPopulate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FPopulate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaps80","download_url":"https://codeload.github.com/shaps80/Populate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241214594,"owners_count":19928337,"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-10-11T13:11:56.007Z","updated_at":"2025-02-28T19:42:55.258Z","avatar_url":"https://github.com/shaps80.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Populate\n\n\n[![Version](https://img.shields.io/cocoapods/v/Populate.svg?style=flat)](http://cocoapods.org/pods/Populate)\n[![License](https://img.shields.io/cocoapods/l/Populate.svg?style=flat)](http://cocoapods.org/pods/Populate)\n[![Platform](https://img.shields.io/cocoapods/p/Populate.svg?style=flat)](http://cocoapods.org/pods/Populate)\n\n## What is Populate?\n\nOften in our iOS apps, we need to populate a `UITableView` or `UICollectionView` with some data.\n\nWhen using CoreData, this is a fairly trivial task since `NSFetchedResultsController` does most of the heavy lifting for us.\n\n## Introducing Populate\n\nHere's a few reason you should start using Populate in your projects now:\n\n- 100% Swift\n- Protocol-Oriented architecture\n- Type-safety (Views, Cells and Data)\n- Supports both **value** and/or **reference** types\n- Multiple **type-safe** cells\n- ArrayDataProvider -- a **type-safe** provider similar to `NSFetchedResultsController`\n    - Filtering\n    - Sectioning\n    - Sorting\n    - Add, remove, update (with type-safety)    \n\nSo lets take a look and see what this looks like in code.\n\n## Example\n\nTo get started, Populate only requires 2 things:\n\n```swift\n// Sets up the coordinator\ninit(dataView: V, cellProvider: DataCoordinatorCellProviding, @noescape dataProvider: () -\u003e D)\n\n// Configure your cells\nfunc dataCoordinator\u003cV: DataView\u003e(dataView: V, cellConfigurationForIndexPath indexPath: NSIndexPath) -\u003e DataCellConfiguration\n```\n\nLets start by settings up the `DataCoordinator`:\n\n```swift\n@import Populate\n\nfinal class PeopleViewController: UITableViewController, DataCoordinatorCellProviding {\n\n  // Popoulate uses a coordinator to manage your view, its cells and the associated data\n  private var dataCoordinator: DataCoordinator\u003cUITableView, ArrayDataProvider\u003cPerson\u003e\u003e?\n\n  override func viewDidLoad() {\n    super.viewDidLoad()\n\n    // We initialize the coordinator with a dataView, cellProvider and a dataProvider configuration\n    dataCoordinator = DataCoordinator(dataView: tableView, cellProvider: self) {\n\n      // So lets seed our dataProvider for convenience\n      let provider = ArrayDataProvider(items: [\n        Person(name: \"Shaps\", address: Address(postcode: \"W5\")),\n        Person(name: \"Anne\", address: Address(postcode: \"W5\")),\n        Person(name: \"Neil\", address: Address(postcode: \"N1\")),\n        Person(name: \"Neil\", address: Address(postcode: \"A1\")),\n        Person(name: \"Daniela\", address: Address(postcode: \"N1\")),\n        Person(name: \"Luciano\", address: Address(postcode: \"SW4\")),\n      ])\n\n      // We can specify a sectionNameKeyPath\n      provider.sectionNameKeyPath = \"address.postcode\"\n\n      // Finally, lets return our provider along with some additional filtering and sort functions\n      return provider\n        .filter { $0.address?.postcode != \"SW4\" }\n        .sort { $0.address?.postcode \u003c $1.address?.postcode }\n        .sort { $0.name \u003c $1.name }\n    }\n  }  \n\n}\n```\n\nOk, so that's a very verbose implementation, yours would probably be a lot cleaner.\n\nNotice the we enforce the type just once on the `var`. This is great, because it means we can get type-safe compiler warnings when things go wrong.\n\nSo, what about the cell for our dataView? Populate provides a type-safe method for configuring your cells:\n\n```swift\nfunc dataCoordinator\u003cV : DataView\u003e(dataView: V, cellConfigurationForIndexPath indexPath: NSIndexPath) -\u003e DataCellConfiguration {\n  return DataCellConfiguration(dataView: dataView, reuseIdentifier: \"Cell\", registerCell: true, indexPath: indexPath, configuration: { (cell: UITableViewCell) in\n    let person = dataCoordinator?.dataProvider.itemAtIndexPath(indexPath)\n    cell.textLabel?.text = person?.name\n  })\n}\n```\n\nOk, so setting up the cell looks complicated, but in actual fact, you're basically just passing the params through to the `DataCellConfiguration`.\n\nThis is a special class that allows multiple, type-safe cells to be configured from a single function.\n\nYou might also notice `registerCell`. This is on by default and basically tells Populate to automatically register the cell (using its type) for you. This means you don't need to register your cell beforehand ;)\n\nNote: This will not work for cells loaded from storyboards or nibs. If you are using one of those, pass false here.\n\n## ArrayDataProvider\n\nA `DataProvider` is simply a protocol, however Populate includes an array-based provider by default.\n\nThis allows you to pass a flat array, and get all the benefits you traditionally get via `NSFetchedResultsController`.\n\nFeatures like, sectioning, sorting, filtering and even mutation are all available. PLUS you get automatic updates reflected in your `DataView`.\n\n```swift\nfunc add(item: T)\nfunc delete(item: T)\nfunc delete(atIndexPath indexPath: NSIndexPath)\nfunc updateItem(atIndexPath indexPath: NSIndexPath, withItem newItem: T)\n```\n\nNote: All mutating functions are type-safe.\n\n## Platforms\n\nPopulate is supported on the following platforms \u0026 versions:\n\n- iOS 8.0+\n\n## Installation\n\nPopulate is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Populate\"\n```\n\n## Author\n\nShaps [@shaps](http://twiter.com/shaps)\n\n## License\n\nPopulate is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fpopulate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaps80%2Fpopulate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fpopulate/lists"}