{"id":18870244,"url":"https://github.com/ofthewolf/anylayout","last_synced_at":"2026-02-14T16:30:16.849Z","repository":{"id":237803804,"uuid":"795274560","full_name":"OfTheWolf/AnyLayout","owner":"OfTheWolf","description":"Create dynamic and modern collections effortlessly without relying on enums with AnyLayout.","archived":false,"fork":false,"pushed_at":"2024-05-03T14:11:08.000Z","size":167,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T23:45:26.983Z","etag":null,"topics":["compositional-layouts","ios","type-erasure","ui-components","uicollectionviewcompositionallayout","uikit"],"latest_commit_sha":null,"homepage":"https://link.medium.com/mjWDs6HLiJb","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/OfTheWolf.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-02T23:45:49.000Z","updated_at":"2024-05-28T10:07:29.000Z","dependencies_parsed_at":"2024-05-03T07:29:31.616Z","dependency_job_id":"3346e821-c282-4894-a98f-e1ab97e3774c","html_url":"https://github.com/OfTheWolf/AnyLayout","commit_stats":null,"previous_names":["ofthewolf/anylayout"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OfTheWolf%2FAnyLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OfTheWolf%2FAnyLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OfTheWolf%2FAnyLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OfTheWolf%2FAnyLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OfTheWolf","download_url":"https://codeload.github.com/OfTheWolf/AnyLayout/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239816505,"owners_count":19701753,"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":["compositional-layouts","ios","type-erasure","ui-components","uicollectionviewcompositionallayout","uikit"],"created_at":"2024-11-08T05:19:27.535Z","updated_at":"2026-02-14T16:30:16.777Z","avatar_url":"https://github.com/OfTheWolf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnyLayout\n\nCreate dynamic and modern collections effortlessly without relying on enums with **AnyLayout**.\n\n**AnyLayout** simplifies building UI collections using `UICollectionViewCompositionalLayout` with type erasure for flexibility.\n\n## Demo\n\u003cimg src=\"demo.jpg\" width=\"375\"/\u003e\n\n## Installation\n\nIntegrate AnyLayout into your project using Swift Package Manager:\n\n**Xcode \u003e File \u003e Add Package Dependencies.. :** https://github.com/OfTheWolf/AnyLayout.git\n\n## Getting Started\n\n1. Inherit from `CollectionViewController`.\n```swift\nclass ViewController: CollectionViewController {}\n```\n\n2. Define sections conforming to `SectionProviding`. Implement the `layout` method to configure the section layout.\n\n```swift\nstruct ListSection: SectionProviding {\n    let id = UUID()\n    \n    // Define section layout here\n    func layout(_ sectionIndex: Int, _ layoutEnvironment: NSCollectionLayoutEnvironment) -\u003e NSCollectionLayoutSection {\n        // Configure section layout\n    }\n}\n```\n\n3. Define items conforming to `ItemProviding`.\n\n```swift\nstruct TextItem: ItemProviding {\n    let text: String\n}\n```\n\n4. Implement cell registration and dequeueing.\n\n```swift\nextension TextCell: Registering {\n    typealias Cell = TextCell\n    typealias Item = TextItem\n\n    /// Boilerplate code\n    static var registration: UICollectionView.CellRegistration\u003cCell, AnyItem\u003e = UICollectionView.CellRegistration\u003cCell, AnyItem\u003e { cell, indexPath, itemIdentifier in\n        let data: Item = itemIdentifier.resolve()\n        cell.configure(with: data)\n    }\n}\n\nextension TextCell: Dequeueing {\n    /// Boilerplate code\n    static func dequeueCell(_ collectionView: UICollectionView, indexPath: IndexPath, item: AnyItem) -\u003e UICollectionViewCell {\n        return collectionView.dequeueConfiguredReusableCell(using: Self.registration, for: indexPath, item: item)\n    }\n}\n```\n\n5. Register your cell types with their corresponding item types.\n\n```swift\n//    MARK: - Override\n    override func registerCells(for collectionView: UICollectionView) {\n        collectionView.register(cell: ImageCell.self, item: ImageItem.self)\n        collectionView.register(cell: TextCell.self, item: TextItem.self)\n    }\n```\n\n6. Prepare the snapshot with your data. \n\n```swift\n    private func loadData() {\n        var snap = NSDiffableDataSourceSnapshot\u003cAnySection, AnyItem\u003e()\n        Mock.data.forEach { data in\n            snap.appendSections([data.section.eraseToAnySection])\n            snap.appendItems(data.items.map(\\.eraseToAnyItem))\n        }\n        dataSource.apply(snap)\n    }\n```\n\n7. Build and run your project.\n\nStart building your dynamic UI collections with ease using AnyLayout!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofthewolf%2Fanylayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofthewolf%2Fanylayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofthewolf%2Fanylayout/lists"}