To run the example project, clone the repo and open Example/Sections.xcodeproj in Xcode. It references the local Sections Swift package directly, so there is nothing else to install.
- Swift 6.0 or newer
- iOS 13 or newer
- macOS 10.15 or newer
Section stores application-level metadata for a table or collection-view
section. Item values only need to conform to Identifiable; they do not need to
conform to Hashable.
enum ProfileSectionID: Hashable {
case friends
}
struct Friend {
let id: String
let name: String
}
enum Item: Identifiable {
case friend(Friend)
var id: String {
switch self {
case .friend(let friend):
return friend.id
}
}
}
let friends = [Friend(id: "alice", name: "Alice")]
let section: Section<ProfileSectionID, Item> = Section(
.friends,
title: "Friends",
items: friends.map(Item.friend)
)Section and item identifiers must be unique when constructing a
SectionBuilder result so it can be used safely with diffable snapshots.
Sections is available through CocoaPods or SPM.
Robert Manson, robmanson@gmail.com
Sections is available under the MIT license. See the LICENSE file for more info.