{"id":18332487,"url":"https://github.com/cellular/modeldatasource-swift","last_synced_at":"2026-01-30T00:07:09.805Z","repository":{"id":33685922,"uuid":"149730017","full_name":"cellular/modeldatasource-swift","owner":"cellular","description":"Handle cells \u0026 content for UITableViews and UICollectionViews","archived":false,"fork":false,"pushed_at":"2022-04-07T05:04:17.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-21T16:21:25.665Z","etag":null,"topics":["cocoapods","datasource","ios","swift","tvos","uicollectionview","uitableview"],"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/cellular.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":"2018-09-21T07:56:55.000Z","updated_at":"2022-05-30T13:42:55.000Z","dependencies_parsed_at":"2022-08-07T23:00:22.089Z","dependency_job_id":null,"html_url":"https://github.com/cellular/modeldatasource-swift","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fmodeldatasource-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fmodeldatasource-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fmodeldatasource-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fmodeldatasource-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cellular","download_url":"https://codeload.github.com/cellular/modeldatasource-swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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":["cocoapods","datasource","ios","swift","tvos","uicollectionview","uitableview"],"created_at":"2024-11-05T19:39:12.461Z","updated_at":"2026-01-30T00:07:09.778Z","avatar_url":"https://github.com/cellular.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD002 MD033 MD041 --\u003e\n\u003ch1 align=\"center\"\u003e\n  \u003ca href=\"https://cellular.de\"\u003e\n    \u003cimg src=\"./.github/cellular.svg\" width=\"300\" max-width=\"50%\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003emodeldatasource\u003cbr\u003e\n\u003c/h1\u003e\n\n\n\u003ch4 align=\"center\"\u003e\nEasily and safely manage your content for data compatible views. The module is capable of handling two dimensional sets of data and simplifies displaying content in section and row/item based views.\nEvery set of data/content and the associated view is stored within a ModelCollection. The ModelCollection inherites from MutableCollection, RandomAccessCollection, RangeReplaceableCollection. Concrete classes conforming against ModelCollection are TableViewDataSource and CollectionViewDataSource.\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/swift-5.0-orange.svg?style=flat\" alt=\"Swift Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://travis-ci.com/cellular/modeldatasource-swift/\"\u003e\n        \u003cimg src=\"https://img.shields.io/travis/com/cellular/networking-swift.svg\" alt=\"Travis Build\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/cellular/modeldatasource-swift\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/cellular/modeldatasource-swift/branch/master/graph/badge.svg\" alt=\"Coverage Report\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://cocoapods.org/pods/CellularModelDataSource\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/v/CellularModelDataSource.svg\" alt=\"CocoaPods Compatible\"\u003e\n    \u003c/a\u003e\n    \n\u003c/p\u003e\n\n\u003c!-- markdownlint-enable MD033 --\u003e\n\n## Example TableViewDataSource\n---\n\n```swift\n// The Example shows how to display two sections, each with 10 cells and a header.\n//\n// To use a data source there a certain requirements that have to be fulfilled:\n// Every cell or header/footer view needs to conform against ModelDataSourceViewDisplayable. \n// They can be stored with their associated content (Model) in either a ModelItem or ModelDecorative\n// which are contstrained to a specific view conforming against ModelDataSourceView (e.g. UITableView). \n// Each section is represented by a ModelSection holding ModelItems and ModelDecoratives.\n//\n// NOTE: The Example folder contains the full code.\n\nvar dataSource = TableViewDataSource()\n\n// Setup the UITableViewView\nlet tableView = UITableView()\ntableView.register(TableViewCell.self)\ntableView.register(DecorativeView.self)\ntableView.dataSource = dataSource\n\n// Items to be displayed in each section-\nlet items: [ModelItem\u003cUITableView\u003e] = (1...10).map { index in\n    return .init(model: .init(color: .gray, title: \"cell # \\(index)\"), cell: TableViewCell.self)\n}\n\n// Build first section\nlet firstHeaderModel: DecorativeView.Model = .init(color: .darkGray, title: \"Header 1\")\nlet firstDecorative: ModelDecorative\u003cUITableView\u003e =  .init(model: firstHeaderModel, view: DecorativeView.self)\nvar firstSection: ModelSection\u003cUITableView\u003e = .init(decorative: firstDecorative, kind: .header)\nfirstSection.append(contentsOf: items)\n\n// Build second section.\nlet secondHeaderModel: DecorativeView.Model = .init(color: .darkGray, title: \"Header 2\")\nlet secondDecorative: ModelDecorative\u003cUITableView\u003e =  .init(model: secondHeaderModel, view: DecorativeView.self)\nvar secondSection: ModelSection\u003cUITableView\u003e = .init(decorative: secondDecorative, kind: .header)\nsecondSection.append(contentsOf: items)\n\n// Append the sections to the TableViewDataSource.\ndataSource.append(contentsOf: [firstSection, secondSection])\n\n// Load the content into the UITableView.\ntableView.reloadData()\n\n```\n\n## Cusomization\n---\nThe default classes conforming against ModelCollection are marked as final and thus cannot be subclassed. Reason being that calling mutating functions (defined in ModelCollection) within the subclass was causing compiler errors. However there are still a few options for customizations.\n\n### 1. Extension on ModelCollection\n```swift\n// Extension on all ModelCollections regardless of the DataSourceView.\nextension ModelCollection {\n    func someCustomCode() { ... }\n    mutating func someCustomMutatingCode() { ... }\n}\n\n// Extension bound to all ModelCollections managing UITableViews.\nextension ModelCollection where DataSourceView == UITableView {\n    func someCustomTableViewCode() { ... }\n    mutating func someCustomMutatingTableViewCode() { ... }\n}\n\n```\n### 2. Decorate an existing datasorce\n```swift\nfinal class CustomDataSource: ModelCollection {\n    typealias DataSourceView = CollectionViewDataSource.DataSourceView\n    typealias Index = CollectionViewDataSource.Index\n    \n    private var dataSource: CollectionViewDatasource\n\n    // MARK: - ModelCollection\n\n    init() {\n        dataSource = .init()\n    }\n\n    var startIndex: Index {\n        return dataSource.startIndex\n    }\n\n    var endIndex: Index {\n        return dataSource.endIndex\n    }\n    \n    // ..... \n\n    // MARK: Custom code\n\n    func someCustomCode() { ... }\n}\n```\n### 3. Full Custom Code\n* Create a custom class / struct and implement every function required to conform against ModelCollection. \n* Make sure that you resolve all associated types.\n* Store your data somewhere (e.g. Array, TableViewDataSource.Buffer)\n\n## Requirements\n---\n* iOS 10.3+\n* tvOS 10.2+\n\n## Installation\n---\n\n```ruby\n### Cocoapods\npod 'CellularModelDataSource'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcellular%2Fmodeldatasource-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcellular%2Fmodeldatasource-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcellular%2Fmodeldatasource-swift/lists"}