diff --git a/Sources/CommonAppleKit/ListView.swift b/Sources/CommonAppleKit/ListView.swift index 3d8964e..27d6bae 100644 --- a/Sources/CommonAppleKit/ListView.swift +++ b/Sources/CommonAppleKit/ListView.swift @@ -8,7 +8,9 @@ import Foundation -public final class ListView: CACollectionView, CACollectionViewDataSource { +public final class ListView: CACollectionView, CACollectionViewDataSource { + private let cellId: String + #if canImport(UIKit) var content: [Any] = [] { didSet { @@ -18,6 +20,7 @@ public final class ListView: CACollectionView, CACol #endif public init(frame: CGRect, itemSize: CGSize, cellId: String) { + self.cellId = cellId let layout = CACollectionViewFlowLayout() layout.itemSize = itemSize #if canImport(AppKit) @@ -48,7 +51,9 @@ public final class ListView: CACollectionView, CACol } #elseif canImport(UIKit) public func collectionView(_ collectionView: CACollectionView, cellForItemAt indexPath: IndexPath) -> CACollectionViewCell { - fatalError() + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) + (cell as? ListViewCell)?.representedObject = content[indexPath.item] + return cell } #endif } diff --git a/Sources/CommonAppleKit/ListViewCell.swift b/Sources/CommonAppleKit/ListViewCell.swift new file mode 100644 index 0000000..c6dfffd --- /dev/null +++ b/Sources/CommonAppleKit/ListViewCell.swift @@ -0,0 +1,13 @@ +// +// ListViewCell.swift +// CommonAppleKit +// +// Created by Roman Podymov on 18/10/2023. +// Copyright © 2023 CommonAppleKit. All rights reserved. +// + +import Foundation + +open class ListViewCell: CACollectionViewCell { + open var representedObject: Any? +}