This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init(){ | |
let layout = UICollectionViewCompositionalLayout { (section, env) -> NSCollectionLayoutSection? in | |
// 1 | |
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200))) | |
// 2 | |
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200)), subitems: [item]) | |
// 3 | |
let section = NSCollectionLayoutSection(group: group) | |
return section | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
if indexPath.row == 0 { | |
//cell.imageView.image = ... | |
//cell.titleLabel.text = ... | |
} else if indexPath.row == 1 { | |
//configure cell type 2 | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
if indexPath.row == 0 { | |
// event when tap on cell at indexPath = 0 | |
} else if indexPath.row == 1 { | |
// event when tap on cell at indexPath = 0 | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
if indexPath.row == 0 { | |
//cell.model = models[indexPath.row] | |
} else if indexPath.row == 1 { | |
//cell.model = models[indexPath.row] | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileViewModel: NSObject, UITableViewDataSource { | |
var items: [ProfileSectionControllerProtocol] = [] | |
func numberOfSections(in tableView: UITableView) -> Int { | |
return items.count | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return items[section].rowCount | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ProfileLoader { | |
func load() -> [ProfileSectionControllerProtocol] | |
} | |
class RemoteProfileLoader: ProfileLoader { | |
func load() -> [ProfileSectionControllerProtocol] { | |
var items = [ProfileSectionControllerProtocol]() | |
guard let data = dataFromFile("ServerData"), let profile = Profile(data: data) else { | |
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileViewModelNamePictureItem { | |
var name: String | |
var pictureUrl: String | |
init(name: String, pictureUrl: String) { | |
self.name = name | |
self.pictureUrl = pictureUrl | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ProfileSectionControllerProtocol { | |
var title: String {get} | |
var cells: [ProfileCellProtocol] {get set} | |
var rowCount: Int {get} | |
init(title: String, cells: [ProfileCellProtocol]) | |
} | |
extension ProfileSectionControllerProtocol { | |
var rowCount: Int { | |
return cells.count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ProfileNamePictureCellController: ProfileCellProtocol { | |
private var cell: NamePictureCell? | |
private let dataModel: ProfileViewModelNamePictureItem | |
init(dataModel: ProfileViewModelNamePictureItem) { | |
self.dataModel = dataModel | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ProfileCellProtocol { | |
func view(_ tableView: UITableView) -> UITableViewCell | |
} |
NewerOlder