{"id":20863562,"url":"https://github.com/ezcater/datasource","last_synced_at":"2025-05-12T09:32:22.022Z","repository":{"id":21128551,"uuid":"80856564","full_name":"ezcater/DataSource","owner":"ezcater","description":"Concise, flexible, and UI independent protocol for data sources","archived":false,"fork":false,"pushed_at":"2024-01-31T17:40:13.000Z","size":173,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":74,"default_branch":"master","last_synced_at":"2024-05-10T22:03:47.319Z","etag":null,"topics":["datasource","ios","swift"],"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/ezcater.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-02-03T18:22:03.000Z","updated_at":"2023-02-16T19:26:14.000Z","dependencies_parsed_at":"2023-12-18T15:47:01.508Z","dependency_job_id":"40987c9d-e57d-4df9-9c0c-a1eb1a1770e1","html_url":"https://github.com/ezcater/DataSource","commit_stats":{"total_commits":48,"total_committers":5,"mean_commits":9.6,"dds":"0.29166666666666663","last_synced_commit":"9184960780592df6c520a978045b66f9dfec2d80"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezcater%2FDataSource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezcater%2FDataSource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezcater%2FDataSource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezcater%2FDataSource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezcater","download_url":"https://codeload.github.com/ezcater/DataSource/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225133169,"owners_count":17425953,"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":["datasource","ios","swift"],"created_at":"2024-11-18T05:29:42.000Z","updated_at":"2024-11-18T05:29:42.752Z","avatar_url":"https://github.com/ezcater.png","language":"Swift","readme":"# Deprecated\n\nThis project is considered deprecated and is no longer receiving updates. You may want to check out Apple's [UICollectionViewDiffableDataSource](https://developer.apple.com/documentation/uikit/uicollectionviewdiffabledatasource).\n\n# DataSource\n\n[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org)\n\nDataSource is a concise and UI independent protocol for representing data sources. It can be used out of the box, but is also extremely flexible in case any customization is required.\n\nAt it's core, `DataSource` is a simple protocol. It requires a `ItemType`, which represents the type of the contained objects.\n\n```swift\npublic protocol DataSource {\n    associatedtype ItemType\n\n    var reloadBlock: ReloadBlock? { get set }\n    var numberOfSections: Int { get }\n\n    func numberOfItems(in section: Int) -\u003e Int\n    func item(at indexPath: IndexPath) -\u003e ItemType?\n    func indexPath(after indexPath: IndexPath) -\u003e IndexPath?\n}\n```\n\nIt uses a closure, `ReloadBlock`, to communicate a `ChangeSet` in the backing data.\n\n```swift\npublic typealias ReloadBlock = (ChangeSet) -\u003e Void\n```\n\nA `ChangeSet` is a set of `Change`s to be performed to the corresponding UI element (`UITableView` or `UICollectionView`).\n\n```swift\npublic enum ChangeSet {\n    case some([Change])\n    case all\n}\n\npublic enum Change {\n    case section(type: ChangeType)\n    case object(type: ChangeType)\n}\n\npublic enum ChangeType {\n    case insert(IndexPath)\n    case delete(IndexPath)\n    case move(IndexPath, IndexPath)\n    case update(IndexPath)\n}\n```\n\n## ListDataSource\n\n`ListDataSource` inherits from `DataSource` and represents a single section backed by an array.\n\n```swift\npublic protocol ListDataSource: DataSource {\n    var items: [ItemType] { get }\n}\n```\n\nIt includes default implementations for:\n\n- `var numberOfSections: Int`\n- `func numberOfItems(in section: Int) -\u003e Int`\n- `func item(at indexPath: IndexPath) -\u003e ItemType?`\n- `func indexPath(after indexPath: IndexPath) -\u003e IndexPath?`\n\n#### Example\n\n```swift\nclass SimpleDataSource: ListDataSource {\n    typealias ItemType = String\n\n    var items = [\n        \"Item 0\",\n        \"Item 1\",\n        \"Item 2\"\n    ]\n\n    var reloadBlock: ReloadBlock?\n}\n```\n\n## SectionedDataSource\n\n`SectionedDataSource` inherits from `DataSource` and represents multiple sections, each backed by a `Section`.\n\n```swift\npublic protocol SectionedDataSource: DataSource {\n    associatedtype SectionType: Section\u003cItemType\u003e\n\n    var sections: [SectionType] { get }\n\n    func section(at index: Int) -\u003e SectionType?\n    func headerTitle(for section: Int) -\u003e String?\n    func footerTitle(for section: Int) -\u003e String?\n}\n```\n\nIt includes default implementations for:\n\n- `var numberOfSections: Int`\n- `func numberOfItems(in section: Int) -\u003e Int`\n- `func item(at indexPath: IndexPath) -\u003e ItemType?`\n- `func indexPath(after indexPath: IndexPath) -\u003e IndexPath?`\n- `func section(at index: Int) -\u003e SectionType?`\n- `func headerTitle(for section: Int) -\u003e String?`\n- `func footerTitle(for section: Int) -\u003e String?`\n\n#### Example\n\n```swift\nclass SimpleDataSource: SectionedDataSource {\n    typealias ItemType = String\n    typealias SectionType = Section\u003cString\u003e\n\n    var sections = [\n        Section(items: [\"Item 0.0\", \"Item 0.1\", \"Item 0.2\"]),\n        Section(items: [\"Item 1.0\", \"Item 1.1\"], headerTitle: \"Header 1\"),\n        Section(items: [\"Item 2.0\"], headerTitle: \"Header 2\", footerTitle: \"Footer 2\")\n    ]\n\n    var reloadBlock: ReloadBlock?\n}\n```\n\n## Section\n\n`Section` objects each represent a single section. It includes an array of `ItemType` items and optionally a header or footer title. It is subclassable if  any additional functionality is needed.\n\n```swift\nopen class Section\u003cItemType\u003e {\n    public var items: [ItemType]\n    public var headerTitle: String?\n    public var footerTitle: String?\n\n    public init(items: [ItemType], headerTitle: String? = nil, footerTitle: String? = nil) {\n        self.items = items\n        self.headerTitle = headerTitle\n        self.footerTitle = footerTitle\n    }\n}\n```\n\n## FetchedDataSource\n\n`FetchedDataSource` inherits from `DataSource` and represents a `NSFetchResultsController` backed list.\n\n```swift\npublic protocol FetchedDataSource: DataSource {\n    associatedtype ItemType: NSFetchRequestResult\n\n    var fetchedResultsController: NSFetchedResultsController\u003cItemType\u003e { get }\n}\n```\n\nIt includes default implementations for:\n\n- `var numberOfSections: Int`\n- `func numberOfItems(in section: Int) -\u003e Int`\n- `func item(at indexPath: IndexPath) -\u003e ItemType?`\n- `func indexPath(after indexPath: IndexPath) -\u003e IndexPath?`\n\n## Requirements\n\nDataSource requires Swift 5.0 and iOS 12.0+\n\n## Installation\n\nDataSource is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"EZDataSource\"\n```\n\n## Author\n\nBrad Smith\n\n## Maintainers\n\nezCater Mobile Team, dev-mobile-team@ezcater.com\n\n## License\n\nDataSource is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezcater%2Fdatasource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezcater%2Fdatasource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezcater%2Fdatasource/lists"}