{"id":321423,"date":"2021-04-14T15:00:07","date_gmt":"2021-04-14T15:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321423"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321423","title":{"rendered":"\u041f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0441\u043f\u0438\u0441\u043a\u0430\u043c \u043d\u0430 UICollectionView"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0423\u0436\u0435 \u0434\u0430\u0432\u043d\u044b\u043c \u0434\u0430\u0432\u043d\u043e, \u0432\u043e \u0432\u0441\u0435\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043d\u0430\u043c \u0433\u0430\u043b\u0430\u043a\u0442\u0438\u043a\u0430\u0445 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 &#8212; \u0431\u0443\u0434\u044c \u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430 \u0435\u0434\u044b \u043d\u0430 \u0422\u0430\u0442\u0443\u0438\u043d\u0435, \u0438\u043c\u043f\u0435\u0440\u0441\u043a\u0430\u044f \u043f\u043e\u0447\u0442\u0430 \u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0438\u043a \u0434\u0436\u0435\u0434\u0430\u044f. \u0421 \u043d\u0435\u0437\u0430\u043f\u0430\u043c\u044f\u0442\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 UI \u043d\u0430 UITableView \u0438 \u043d\u0435 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438\u0441\u044c. <\/p>\n<p>\u041a\u043e\u043f\u0438\u043b\u0438\u0441\u044c \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0433\u0438 \u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u043e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u043e \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u0445. \u0418 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 infinite scroll \u0434\u0438\u0437\u0430\u0439\u043d, \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438: \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u0438 \u0434\u0430\u0442\u044c \u043e\u0442\u043f\u043e\u0440 \u0442\u0438\u0440\u0430\u043d\u0438\u0438 UITableViewDataSource \u0438 UITableViewDelegate.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f?<\/h2>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u0431\u044b\u0432\u0430\u043b\u0438 \u0432 \u0442\u0435\u043d\u0438, \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e\u0431\u0430\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u0445 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c. <\/p>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0435\u043a \u0438\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443?  \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043c\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u043f\u0440\u0435\u043c\u0441\u044f \u0432 \u043d\u0438\u0437\u043a\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u0441\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0435\u0439\u0430\u0443\u0442\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a \u043b\u0438 \u0441\u0442\u0440\u0430\u0448\u043d\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u043e\u043d\u0438 \u0432 \u0441\u0435\u0431\u0435 \u0442\u0430\u044f\u0442? \u041c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043b\u0438.<\/p>\n<ul>\n<li>\n<p>\u042f\u0447\u0435\u0439\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b: content view, group editing view, slide actions view, accessory view.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 UICollectionView \u0434\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0435 API \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0445\u043e\u0436 \u0441 UITableView.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u043b\u0435\u0439\u0430\u0443\u0442\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0438\u0448\u043d\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0430\u0441\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Pull to refresh<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435 \u043b\u0430\u0433\u043e\u0432 \u043f\u0440\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u043e\u043b\u043b\u0430 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0432 \u0445\u043e\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0440\u0430\u0437\u0432\u0435\u044f\u043b\u0438\u0441\u044c.<\/p>\n<p>\u0418\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b54\/7d4\/cb3\/b547d4cb305256c69ec45eeaf8b29b4d.jpeg\" width=\"320\" height=\"320\"><figcaption><\/figcaption><\/figure>\n<h2>\u0410\u0434\u0430\u043f\u0442\u0435\u0440\u044b<\/h2>\n<p>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u044d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u043b\u0438 \u0432\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0431\u043e\u0438\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430 \u0441 \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441\u0430\u043c\u0438 \u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u043e \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0442\u0440\u043e\u043a?  \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u043d\u0430 UITableView.<\/p>\n<pre><code class=\"swift\">final class CurrencyViewController: UIViewController {      var tableView = UITableView()     var items: [ViewModel] = []      func setup() {         tableView.delegate = self         tableView.dataSource = self         tableView.backgroundColor = .white     \t\ttableView.rowHeight = 72.0                          tableView.contentInset = .init(top: Constants.topSpacing, left: 0, bottom: Constants.bottomSpacing, right: 0)          tableView.reloadData()     }  }  extension CurrencyViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         output.didSelectBalance(at: indexPath.row)     }  }  extension CurrencyViewController: UITableViewDataSource {      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {         items.count     }      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {                 let cell = tableView.dequeueReusable(cell: object.cellClass, at: indexPath)         cell.setup(with: object)                  return cell     }  }  extension UITableView {     func dequeueReusable(cell type: UITableViewCell.Type, at indexPath: IndexPath) -&gt; UITableViewCell {         if let cell: UITableViewCell = self.dequeueReusableCell(withIdentifier: type.name()) {             return cell         }          self.register(cell: type)          let cell: UITableViewCell = self.dequeueReusableCell(withIdentifier: type.name(), for: indexPath)          return cell     }      private func register(cell type: UITableViewCell.Type) {         let identifier: String = type.name()                  self.register(type, forCellReuseIdentifier: identifier)      } } <\/code><\/pre>\n<p>\u041f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c <s>\u0434\u0436\u0435\u0434\u0430\u0438<\/s> \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d <strong>\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/strong> \u043d\u0430\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0430\u0448 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u044d\u0442\u0438\u043c \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0441\u044f.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"swift\">private let listAdapter = CurrencyVerticalListAdapter() private let collectionView = UICollectionView(     frame: .zero,     collectionViewLayout: UICollectionViewFlowLayout() )  private var viewModel: BalancePickerViewModel  func setup() {     listAdapter.setup(collectionView: collectionView)     collectionView.backgroundColor = .c0     collectionView.contentInset = .init(top: Constants.topSpacing, left: 0, bottom: Constants.bottomSpacing, right: 0)      listAdapter.onSelectItem = output.didSelectBalance     listAdapter.heightMode = .fixed(height: 72.0)     listAdapter.spacing = 8.0     listAdapter.reload(items: viewModel.items) } <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441.  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 (\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439) \u043a\u043b\u0430\u0441\u0441 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u043f\u0438\u0441\u043a\u043e\u0432:<\/p>\n<pre><code class=\"swift\">public class ListAdapter&lt;Cell&gt; : NSObject, ListAdapterInput, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDragDelegate, UICollectionViewDropDelegate, UIScrollViewDelegate where Cell : UICollectionViewCell, Cell : DesignKit.AnimatedConfigurableView, Cell : DesignKit.RegistrableView {      public typealias Model = Cell.Model     public typealias ResizeCallback = (_ insertions: [Int], _ removals: [Int], _ skipNext: Bool) -&gt; Void     public typealias SelectionCallback = ((Int) -&gt; Void)?     public typealias ReadyCallback = () -&gt; Void      public enum DragAndDropStyle {         case reorder         case none     }      public var dragAndDropStyle: DragAndDropStyle { get set }      internal var headerModel: ListHeaderView.Model?      public var spacing: CGFloat      public var itemSizeCacher: UICollectionItemSizeCaching?      public var onSelectItem: ((Int) -&gt; Void)?     public var onDeselectItem: ((Int) -&gt; Void)?     public var onWillDisplayCell: ((Cell) -&gt; Void)?     public var onDidEndDisplayingCell: ((Cell) -&gt; Void)?     public var onDidScroll: ((CGPoint) -&gt; Void)?     public var onDidEndDragging: ((CGPoint) -&gt; Void)?     public var onWillBeginDragging: (() -&gt; Void)?     public var onDidEndDecelerating: (() -&gt; Void)?     public var onDidEndScrollingAnimation: (() -&gt; Void)?     public var onReorderIndexes: (((Int, Int)) -&gt; Void)?     public var onWillBeginReorder: ((IndexPath) -&gt; Void)?     public var onReorderEnter: (() -&gt; Void)?     public var onReorderExit: (() -&gt; Void)?      internal func subscribe(_ subscriber: AnyObject, onResize: @escaping ResizeCallback)     internal func unsubscribe(fromResize subscriber: AnyObject)     internal func subscribe(_ subscriber: AnyObject, onReady: @escaping ReadyCallback)     internal func unsubscribe(fromReady subscriber: AnyObject)      internal weak var collectionView: UICollectionView?      public internal(set) var items: [Model] { get set }      public func setup(collectionView: UICollectionView)      public func setHeader(_ model: ListHeaderView.Model)      public subscript(index: Int) -&gt; Model? { get }      public func reload(items: [Model], needsRedraw: Bool = true)      public func insertItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func appendItem(_ item: Model, allowDynamicModification: Bool = true)     public func deleteItem(at index: Int, allowDynamicModification: Bool = true)     public func deleteItemsIfNeeded(at range: PartialRangeFrom&lt;Int&gt;)     public func deleteItems(at indexes: [Int], allowDynamicModification: Bool = true)     public func updateItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at range: PartialRangeFrom&lt;Int&gt;, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at indexes: [Int], allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [(index: Int, element: Model)], allowDynamicModification: Bool = true)     public func moveItem(at index: Int, to newIndex: Int)      public func performBatchUpdates(updates: @escaping (ListAdapter) -&gt; Void, completion: ((Bool) -&gt; Void)?)     public func performBatchUpdates(updates: () -&gt; Void, completion: ((Bool) -&gt; Void)?)     }  public typealias ListAdapterCellConstraints = UICollectionViewCell &amp; RegistrableView &amp; AnimatedConfigurableView public typealias VerticalListAdapterCellConstraints = ListAdapterCellConstraints &amp; HeightMeasurableView public typealias HorizontalListAdapterCellConstraints = ListAdapterCellConstraints &amp; WidthMeasurableView <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f.<\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0434\u0451\u0442 \u0431\u043b\u043e\u043a typealias&#8217;\u043e\u0432 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b.<\/p>\n<p>DragAndDropStyle \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>headerModel &#8212; \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/p>\n<p>spacing &#8212; \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0451\u0442 \u0431\u043b\u043e\u043a \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 onReady \u0438 onResize \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u0442\u0430\u043b\u0430 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u0440\u0430\u0431\u043e\u0442\u0435, \u0438 \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u0437-\u0437\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>collectionView, setup(collectionView:) &#8212; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0435\u0451 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438<\/p>\n<p>items &#8212; \u043d\u0430\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<p>setHeader &#8212; \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/p>\n<p>itemSizeCacher &#8212; \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u0435\u0444\u043e\u043b\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"swift\">final class DefaultItemSizeCacher: UICollectionItemSizeCaching {          private var sizeCache: [IndexPath: CGSize] = [:]          func itemSize(cachedAt indexPath: IndexPath) -&gt; CGSize? {         sizeCache[indexPath]     }          func cache(itemSize: CGSize, at indexPath: IndexPath) {         sizeCache[indexPath] = itemSize     }          func invalidateItemSizeCache(at indexPath: IndexPath) {         sizeCache[indexPath] = nil     }          func invalidate() {         sizeCache = [:]     }      } <\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u044b \u043f\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0435\u043a \u043f\u043e \u043e\u0441\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e4e\/403\/ad3\/e4e403ad3196d9180de41452287f7f82.png\" width=\"1352\" height=\"428\"><figcaption><\/figcaption><\/figure>\n<h2>AnyListAdapter<\/h2>\n<p>\u0414\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c, \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u041d\u043e \u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043c\u044b \u043d\u0435 \u0437\u0440\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043f\u0440\u043e infinite-scroll \u0434\u0438\u0437\u0430\u0439\u043d. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430(\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0435\u0442\u0438) \u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u044c\u044e? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 AnyListAdapter.<\/p>\n<pre><code class=\"swift\">public typealias AnyListSliceAdapter = ListSliceAdapter&lt;AnyListCell&gt;  public final class AnyListAdapter : ListAdapter&lt;AnyListCell&gt;, UICollectionViewDelegateFlowLayout {      public var dimensionCalculationMode: DesignKit.AnyListAdapter.DimensionCalculationMode      public let axis: Axis      public init&lt;Cell&gt;(dynamicCellType: Cell.Type) where Cell : UICollectionViewCell, Cell : DesignKit.AnimatedConfigurableView, Cell : DesignKit.HeightMeasurableView, Cell : DesignKit.RegistrableView      public init&lt;Cell&gt;(dynamicCellType: Cell.Type) where Cell : UICollectionViewCell, Cell : DesignKit.AnimatedConfigurableView, Cell : DesignKit.RegistrableView, Cell : DesignKit.WidthMeasurableView }  public extension AnyListAdapter {      convenience public init&lt;C1, C2&gt;(dynamicCellTypes: (C1.Type, C2.Type)) where C1 : UICollectionViewCell, C1 : DesignKit.AnimatedConfigurableView, C1 : DesignKit.HeightMeasurableView, C1 : DesignKit.RegistrableView, C2 : UICollectionViewCell, C2 : DesignKit.AnimatedConfigurableView, C2 : DesignKit.HeightMeasurableView, C2 : DesignKit.RegistrableView      convenience public init&lt;C1, C2, C3&gt;(dynamicCellTypes: (C1.Type, C2.Type, C3.Type)) where C1 : UICollectionViewCell, C1 : DesignKit.AnimatedConfigurableView, C1 : DesignKit.HeightMeasurableView, C1 : DesignKit.RegistrableView, C2 : UICollectionViewCell, C2 : DesignKit.AnimatedConfigurableView, C2 : DesignKit.HeightMeasurableView, C2 : DesignKit.RegistrableView, C3 : UICollectionViewCell, C3 : DesignKit.AnimatedConfigurableView, C3 : DesignKit.HeightMeasurableView, C3 : DesignKit.RegistrableView      convenience public init&lt;C1, C2&gt;(dynamicCellTypes: (C1.Type, C2.Type)) where C1 : UICollectionViewCell, C1 : DesignKit.AnimatedConfigurableView, C1 : DesignKit.RegistrableView, C1 : DesignKit.WidthMeasurableView, C2 : UICollectionViewCell, C2 : DesignKit.AnimatedConfigurableView, C2 : DesignKit.RegistrableView, C2 : DesignKit.WidthMeasurableView      convenience public init&lt;C1, C2, C3&gt;(dynamicCellTypes: (C1.Type, C2.Type, C3.Type)) where C1 : UICollectionViewCell, C1 : DesignKit.AnimatedConfigurableView, C1 : DesignKit.RegistrableView, C1 : DesignKit.WidthMeasurableView, C2 : UICollectionViewCell, C2 : DesignKit.AnimatedConfigurableView, C2 : DesignKit.RegistrableView, C2 : DesignKit.WidthMeasurableView, C3 : UICollectionViewCell, C3 : DesignKit.AnimatedConfigurableView, C3 : DesignKit.RegistrableView, C3 : DesignKit.WidthMeasurableView }  public extension AnyListAdapter {      public enum Axis {          case horizontal          case vertical     }      public enum DimensionCalculationMode {          case automatic          case fixed(constant: CGFloat? = nil)     } } <\/code><\/pre>\n<p>\u041a\u0430\u043a \u043d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, AnyListAdapter \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u044f\u0447\u0435\u0439\u043a\u0438. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u044f\u0447\u0435\u0435\u043a, \u043d\u043e \u043e\u043d\u0438 \u0432\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u0434\u043b\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043b\u0435\u0439\u0430\u0443\u0442\u0430, \u043b\u0438\u0431\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e. \u0423\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 HeightMeasurableView \u0438 WidthMeasurableView.<\/p>\n<pre><code class=\"swift\">public protocol HeightMeasurableView where Self: ConfigurableView {     static func calculateHeight(model: Model, width: CGFloat) -&gt; CGFloat     func measureHeight(model: Model, width: CGFloat) -&gt; CGFloat    }  public protocol WidthMeasurableView where Self: ConfigurableView {     static func calculateWidth(model: Model, height: CGFloat) -&gt; CGFloat     func measureWidth(model: Model, height: CGFloat) -&gt; CGFloat } <\/code><\/pre>\n<p>\u0423 \u0441\u043f\u0438\u0441\u043a\u0430 \u0442\u0430\u043a \u0436\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0432\u044b\u0441\u043e\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439(\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 \u0438\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438)<\/p>\n<\/li>\n<li>\n<p>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 (\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u0435\u0439\u0430\u0443\u0442\u0430).<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0438\u043b\u0430 \u0432\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u044f\u0447\u0435\u0439\u043a\u0438-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 AnyListCell \u0441\u043f\u0440\u044f\u0442\u0430\u043d\u0430.<\/p>\n<pre><code class=\"swift\">public class AnyListCell: ListAdapterCellConstraints {          \/\/ MARK: - ConfigurableView          public enum Model {         case `static`(UIView)         case `dynamic`(DynamicModel)     }          public func configure(model: Model, animated: Bool, completion: (() -&gt; Void)?) {         switch model {         case let .static(view):             guard !contentView.subviews.contains(view) else { return }                          clearSubviews()             contentView.addSubview(view)             view.layout {                 $0.pin(to: contentView)             }          case let .dynamic(model):             model.configure(cell: self)         }          completion?()     }          \/\/ MARK: - RegistrableView          public static var registrationMethod: ViewRegistrationMethod = .class          public override func prepareForReuse() {         super.prepareForReuse()                  clearSubviews()     }          private func clearSubviews() {         contentView.subviews.forEach {             $0.removeFromSuperview()         }     }      } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0432\u0438\u0434\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438: \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439.<\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0432\u044c\u044e.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0436\u0435 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440 \u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u0432\u044b\u0441\u043e\u0442\u044b, \u0441\u0442\u0438\u0440\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0430\u043c \u0442\u0438\u043f \u044f\u0447\u0435\u0439\u043a\u0438. \u0412 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u043a\u0430\u043a \u044f\u0447\u0435\u0439\u043a\u0438, \u0442\u0430\u043a \u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430: <strong><em>Any<\/em><\/strong>.<\/p>\n<pre><code class=\"swift\">struct DynamicModel {     public init&lt;Cell&gt;(model: Cell.Model,                     cell: Cell.Type) {             \/\/ ...     }      func dequeueReusableCell(from collectionView: UICollectionView, for indexPath: IndexPath) -&gt; UICollectionViewCell     func configure(cell: UICollectionViewCell)     func calcucalteDimension(otherDimension: CGFloat) -&gt; CGFloat     func measureDimension(otherDimension: CGFloat) -&gt; CGFloat } <\/code><\/pre>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438: \u0442\u0435\u0433\u0438, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440 \u0434\u043b\u044f \u0438\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<pre><code class=\"swift\">private let listAdapter = AnyListAdapter(     dynamicCellTypes: (CommonCollectionViewCell.self, OperationCell.self) )  func configureSearchResults(with model: OperationsSearchViewModel) {     var items: [AnyListCell.Model] = []      model.sections.forEach {         let header = VerticalSectionHeaderView().configured(with: $0.header)         items.append(.static(header))         switch $0 {         case .tags(nil), .operations(nil):             items.append(                 .static(OperationsNoResultsView().configured(with: Localisation.feed_search_no_results))             )         case let .tags(models?):             items.append(                 contentsOf: models.map {                     .dynamic(.init(                         model: $0,                         cell: CommonCollectionViewCell.self                     ))                 }             )         case .operations(let models?):             items.append(                 contentsOf: models.map {                     .dynamic(.init(                         model: $0,                         cell: OperationCell.self                     ))                 }             )         }     }      UIView.performWithoutAnimation {         listAdapter.deleteItemsIfNeeded(at: 0...)         listAdapter.reloadItems(items, at: 0...)     } } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0442\u0430\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u043a\u0440\u0430\u043d\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0442\u0435\u0440\u044f\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0447\u0435\u0435\u043a.<\/p>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a54\/c1a\/b3d\/a54c1ab3d701c145cf0c103187a55e93.gif\" alt=\"   \" title=\"   \" width=\"800\" height=\"1723\"><figcaption>   <\/figcaption><\/figure>\n<h2>\u0421\u043f\u0438\u0441\u043e\u043a \u043f\u043e \u043a\u0443\u0441\u043a\u0430\u043c<\/h2>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u044d\u043a\u0440\u0430\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u0434\u0435\u043b\u0435\u043d \u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u0438. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 \u043f\u043b\u0430\u043d\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0438.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/296\/148\/b93\/296148b9355e64cb5f7003bf0fbc8245.jpg\" width=\"484\" height=\"136\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 AnyListAdapter \u043d\u0435 \u0434\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 NSInternalInconsistencyException \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u0438\u0437 \u0442\u043e\u0439 \u0441\u0435\u043a\u0446\u0438\u0438. \u041f\u043e\u0438\u0441\u043a \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u044d\u0442\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 ArraySlice, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435  \u044f\u0437\u044b\u043a\u0430 Swift.<\/p>\n<p>\u0426\u0435\u043b\u044c\u044e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u0432\u043e\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430.<\/p>\n<pre><code class=\"swift\">let subjectsSectionHeader = SectionHeaderView(title: \"Subjects\") let pocketsSectionHeader = SectionHeaderView(title: \"Pockets\") let cardsSectionHeader = SectionHeaderView(title: \"Cards\") let categoriesHeader = SectionHeaderView(title: \"Categories\")  let list = AnyListAdapter() listAdapter.reloadItems([     .static(subjectsSectionHeader),     .static(pocketsSectionHeader)     .static(cardsSectionHeader),     .static(categoriesHeader) ]) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u044d\u0442\u0438 \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e.<\/p>\n<pre><code class=\"swift\">class PocketsViewController: UIViewController {     var listAdapter: AnyListSliceAdapter! {         didSet { \t\t\t\t\t\treload()         }     }      var pocketsService = PocketsService()      func reload() {         pocketsService.fetch { pockets, error in             guard let pocket = pockets else { return }              listAdapter.reloadItems(                 pockets.map { .dynamic(.init(model: $0, cell: PocketCell.self)) },                 at: 1...             )         }     }      func didTapRemoveButton(at index: Int) { \t\t\t\tlistAdapter.deleteItemsIfNeeded(at: index)     } }  let subjectsVC = PocketsViewController() subjectsVC.listAdapter = list[1..&lt;2] <\/code><\/pre>\n<p>\u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0443\u0441\u043e\u043a \u0441\u043f\u0438\u0441\u043a\u0430: \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0433\u0440\u0430\u043d\u0438\u0446 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<pre><code class=\"swift\">public extension ListAdapter {     subscript(range: Range&lt;Int&gt;) -&gt; ListSliceAdapter&lt;Cell&gt; {         .init(listAdapter: self, range: range)     }      init(listAdapter: ListAdapter&lt;Cell&gt;,                range: Range&lt;Int&gt;) {         self.listAdapter = listAdapter         self.sliceRange = range          let updateSliceRange: ([Int], [Int], Bool) -&gt; Void = { [unowned self] insertions, removals, skipNextResize in             self.handleParentListChanges(insertions: insertions, removals: removals)             self.skipNextResize = skipNextResize         }          let enableWorkingWithSlice = { [weak self] in             self?.onReady?()             return         }          listAdapter.subscribe(self, onResize: updateSliceRange)         listAdapter.subscribe(self, onReady: enableWorkingWithSlice)     } } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u0435\u043a\u0446\u0438\u0435\u0439 \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044f \u043e\u0431 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u044f\u0441\u044c \u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0440\u0435\u043d\u0434\u0436\u0435 \u0441\u043b\u0430\u0439\u0441\u0430, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043b\u0430\u0439\u0441 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e ListAdapter.<\/p>\n<pre><code class=\"swift\">public final class ListSliceAdapter&lt;Cell&gt; : ListAdapterInput where Cell : UICollectionViewCell, Cell : ConfigurableView, Cell : RegistrableView {      public var items: [Model] { get }      public var onReady: (() -&gt; Void)?      internal private(set) var sliceRange: Range&lt;Int&gt; { get set }      internal init(listAdapter: ListAdapter&lt;Cell&gt;, range: Range&lt;Int&gt;)     convenience internal init(listAdapter: ListAdapter&lt;Cell&gt;, index: Int)      public subscript(index: Int) -&gt; Model? { get }      public func reload(items: [Model], needsRedraw: Bool = true)     public func insertItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func appendItem(_ item: Model, allowDynamicModification: Bool = true)     public func deleteItem(at index: Int, allowDynamicModification: Bool = true)     public func deleteItemsIfNeeded(at range: PartialRangeFrom&lt;Int&gt;)     public func deleteItems(at indexes: [Int], allowDynamicModification: Bool = true)     public func updateItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at range: PartialRangeFrom&lt;Int&gt;, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at indexes: [Int], allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [(index: Int, element: Model)], allowDynamicModification: Bool = true)     public func moveItem(at index: Int, to newIndex: Int)     public func performBatchUpdates(updates: () -&gt; Void, completion: ((Bool) -&gt; Void)?) } <\/code><\/pre>\n<p>\u041d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/p>\n<pre><code class=\"swift\">public func deleteItemsIfNeeded(at range: PartialRangeFrom&lt;Int&gt;) {     guard canDelete(index: range.lowerBound) else { return }      let start = globalIndex(of: range.lowerBound)     let end = sliceRange.upperBound - 1      listAdapter.deleteItems(at: Array(start...end)) } <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u0443\u044e \u0440\u043e\u043b\u044c \u0438\u0433\u0440\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u0443\u0441\u043a\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0433\u043e ListAdapter.<\/p>\n<pre><code class=\"swift\">public class ListAdapter {     \/\/ ...      var resizeSubscribers = NSMapTable&lt;AnyObject, NSObjectWrapper&lt;ResizeCallback&gt;&gt;.weakToStrongObjects() }  extension ListAdapter { \t\tpublic func appendItem(_ item: Model) {         let index = items.count                 let changes = {             self.items.append(item)             self.handleSizeChange(insert: self.items.endIndex)             self.collectionView?.insertItems(at: [IndexPath(item: index, section: 0)])         }                  if #available(iOS 13, *) {             changes()         } else {             performBatchUpdates(updates: changes, completion: nil)         }     }      func handleSizeChange(removal index: Int) {         notifyAboutResize(removals: [index])     }      func handleSizeChange(insert index: Int) {         notifyAboutResize(insertions: [index])     }      func notifyAboutResize(insertions: [Int] = [], removals: [Int] = [], skipNextResize: Bool = false) {         resizeSubscribers             .objectEnumerator()?             .allObjects             .forEach {                 ($0 as? NSObjectWrapper&lt;ResizeCallback&gt;)?.object(insertions, removals, skipNextResize)             }     }      func shiftSubscribers(after index: Int, by shiftCount: Int) {         guard shiftCount &gt; 0 else { return }          notifyAboutResize(             insertions: Array(repeating: index, count: shiftCount),             skipNextResize: true         )     } } <\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u043c \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 <s>\u0442\u0432\u0438\u0442\u0442\u0435\u0440\u0430 \u0441\u043e\u0432\u0435\u0442\u0430 \u0434\u0436\u0435\u0434\u0430\u0435\u0432<\/s> \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>\u041d\u0435 \u043f\u043e\u043c\u0435\u0448\u0430\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0437\u0440\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0432\u0435\u0436\u0438\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0431\u0435\u043d\u0438\u0444\u0438\u0442\u044b. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u043e\u0432. \u0412 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c \u043b\u0435\u0439\u0430\u0443\u0442\u043e\u043c: \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439. \u0415\u0441\u043b\u0438 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0441 \u0432\u0434\u0440\u0443\u0433 \u043d\u0435 \u0443\u0441\u0442\u0440\u043e\u0438\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u0438\u043b\u0438 \u0431\u0430\u0433\u0438 \u043d\u043e\u0432\u043e\u0439 iOS) \u0443 UICollectionView, \u0442\u043e \u043b\u0435\u0433\u043a\u043e \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0438 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<p>\u0418, \u0447\u0442\u043e <s>\u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445<\/s> \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 &#8212; \u0441\u0435\u0442\u0430\u043f \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 10 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u043e\u044f\u043b\u0438\u0441\u044c \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u044d\u043a\u0440\u0430\u043d \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u043c\u0435\u043b\u043e \u043f\u0438\u0448\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0440\u0435\u0442\u0438\u0439 \u044d\u043a\u0440\u0430\u043d( ~30%) \u043d\u0430 \u0441\u043f\u0438\u0441\u043a\u0430\u0445, \u0432\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0433\u043e \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432. \u0410 \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0432 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0443\u044e \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e &#8212; \u0442\u043e \u043a \u0432\u0430\u0448\u0438\u043c \u0443\u0441\u043b\u0443\u0433\u0430\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u0443\u0441\u043a\u0430 \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u0444\u0440\u0443\u043a\u0442 \u0434\u0436\u043e\u0433\u043e\u043d \u0432 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u043f\u043e\u0438\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0435\u0434\u044b \u043d\u0430 \u0422\u0430\u0442\u0443\u0438\u043d\u0435, \u0430 \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0436\u0435\u0434\u0430\u0439 &#8212; \u0442\u043e \u0431\u0435\u0437 \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0434\u043e\u0441\u043a\u0440\u043e\u043b\u0438\u0442\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u043e\u0442 \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430 \u0419\u043e\u0434\u044b.<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d2\/686\/7f6\/0d26867f6117faa13c7b6dc1a6e578d6.jpg\" width=\"944\" height=\"925\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/vivid_money\/blog\/552418\/\"> https:\/\/habr.com\/ru\/company\/vivid_money\/blog\/552418\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0423\u0436\u0435 \u0434\u0430\u0432\u043d\u044b\u043c \u0434\u0430\u0432\u043d\u043e, \u0432\u043e \u0432\u0441\u0435\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043d\u0430\u043c \u0433\u0430\u043b\u0430\u043a\u0442\u0438\u043a\u0430\u0445 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 &#8212; \u0431\u0443\u0434\u044c \u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430 \u0435\u0434\u044b \u043d\u0430 \u0422\u0430\u0442\u0443\u0438\u043d\u0435, \u0438\u043c\u043f\u0435\u0440\u0441\u043a\u0430\u044f \u043f\u043e\u0447\u0442\u0430 \u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0438\u043a \u0434\u0436\u0435\u0434\u0430\u044f. \u0421 \u043d\u0435\u0437\u0430\u043f\u0430\u043c\u044f\u0442\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 UI \u043d\u0430 UITableView \u0438 \u043d\u0435 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438\u0441\u044c. <\/p>\n<p>\u041a\u043e\u043f\u0438\u043b\u0438\u0441\u044c \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0433\u0438 \u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u043e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u043e \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u0445. \u0418 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 infinite scroll \u0434\u0438\u0437\u0430\u0439\u043d, \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438: \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u0438 \u0434\u0430\u0442\u044c \u043e\u0442\u043f\u043e\u0440 \u0442\u0438\u0440\u0430\u043d\u0438\u0438 UITableViewDataSource \u0438 UITableViewDelegate.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f?<\/h2>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u0431\u044b\u0432\u0430\u043b\u0438 \u0432 \u0442\u0435\u043d\u0438, \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e\u0431\u0430\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u0445 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c. <\/p>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0435\u043a \u0438\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443?  \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043c\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u043f\u0440\u0435\u043c\u0441\u044f \u0432 \u043d\u0438\u0437\u043a\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u0441\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0435\u0439\u0430\u0443\u0442\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a \u043b\u0438 \u0441\u0442\u0440\u0430\u0448\u043d\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u043e\u043d\u0438 \u0432 \u0441\u0435\u0431\u0435 \u0442\u0430\u044f\u0442? \u041c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043b\u0438.<\/p>\n<ul>\n<li>\n<p>\u042f\u0447\u0435\u0439\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b: content view, group editing view, slide actions view, accessory view.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 UICollectionView \u0434\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0435 API \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0445\u043e\u0436 \u0441 UITableView.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u043b\u0435\u0439\u0430\u0443\u0442\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0438\u0448\u043d\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0430\u0441\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Pull to refresh<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435 \u043b\u0430\u0433\u043e\u0432 \u043f\u0440\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u043e\u043b\u043b\u0430 \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0432 \u0445\u043e\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0440\u0430\u0437\u0432\u0435\u044f\u043b\u0438\u0441\u044c.<\/p>\n<p>\u0418\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>\u0410\u0434\u0430\u043f\u0442\u0435\u0440\u044b<\/h2>\n<p>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u044d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u043b\u0438 \u0432\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0431\u043e\u0438\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430 \u0441 \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441\u0430\u043c\u0438 \u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u043e \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0442\u0440\u043e\u043a?  \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u043d\u0430 UITableView.<\/p>\n<pre><code class=\"swift\">final class CurrencyViewController: UIViewController {      var tableView = UITableView()     var items: [ViewModel] = []      func setup() {         tableView.delegate = self         tableView.dataSource = self         tableView.backgroundColor = .white     \t\ttableView.rowHeight = 72.0                          tableView.contentInset = .init(top: Constants.topSpacing, left: 0, bottom: Constants.bottomSpacing, right: 0)          tableView.reloadData()     }  }  extension CurrencyViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         output.didSelectBalance(at: indexPath.row)     }  }  extension CurrencyViewController: UITableViewDataSource {      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {         items.count     }      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {                 let cell = tableView.dequeueReusable(cell: object.cellClass, at: indexPath)         cell.setup(with: object)                  return cell     }  }  extension UITableView {     func dequeueReusable(cell type: UITableViewCell.Type, at indexPath: IndexPath) -&gt; UITableViewCell {         if let cell: UITableViewCell = self.dequeueReusableCell(withIdentifier: type.name()) {             return cell         }          self.register(cell: type)          let cell: UITableViewCell = self.dequeueReusableCell(withIdentifier: type.name(), for: indexPath)          return cell     }      private func register(cell type: UITableViewCell.Type) {         let identifier: String = type.name()                  self.register(type, forCellReuseIdentifier: identifier)      } } <\/code><\/pre>\n<p>\u041f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c <s>\u0434\u0436\u0435\u0434\u0430\u0438<\/s> \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d <strong>\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/strong> \u043d\u0430\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0430\u0448 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u044d\u0442\u0438\u043c \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0441\u044f.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"swift\">private let listAdapter = CurrencyVerticalListAdapter() private let collectionView = UICollectionView(     frame: .zero,     collectionViewLayout: UICollectionViewFlowLayout() )  private var viewModel: BalancePickerViewModel  func setup() {     listAdapter.setup(collectionView: collectionView)     collectionView.backgroundColor = .c0     collectionView.contentInset = .init(top: Constants.topSpacing, left: 0, bottom: Constants.bottomSpacing, right: 0)      listAdapter.onSelectItem = output.didSelectBalance     listAdapter.heightMode = .fixed(height: 72.0)     listAdapter.spacing = 8.0     listAdapter.reload(items: viewModel.items) } <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441.  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 (\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439) \u043a\u043b\u0430\u0441\u0441 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u043f\u0438\u0441\u043a\u043e\u0432:<\/p>\n<pre><code class=\"swift\">public class ListAdapter&lt;Cell&gt; : NSObject, ListAdapterInput, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDragDelegate, UICollectionViewDropDelegate, UIScrollViewDelegate where Cell : UICollectionViewCell, Cell : DesignKit.AnimatedConfigurableView, Cell : DesignKit.RegistrableView {      public typealias Model = Cell.Model     public typealias ResizeCallback = (_ insertions: [Int], _ removals: [Int], _ skipNext: Bool) -&gt; Void     public typealias SelectionCallback = ((Int) -&gt; Void)?     public typealias ReadyCallback = () -&gt; Void      public enum DragAndDropStyle {         case reorder         case none     }      public var dragAndDropStyle: DragAndDropStyle { get set }      internal var headerModel: ListHeaderView.Model?      public var spacing: CGFloat      public var itemSizeCacher: UICollectionItemSizeCaching?      public var onSelectItem: ((Int) -&gt; Void)?     public var onDeselectItem: ((Int) -&gt; Void)?     public var onWillDisplayCell: ((Cell) -&gt; Void)?     public var onDidEndDisplayingCell: ((Cell) -&gt; Void)?     public var onDidScroll: ((CGPoint) -&gt; Void)?     public var onDidEndDragging: ((CGPoint) -&gt; Void)?     public var onWillBeginDragging: (() -&gt; Void)?     public var onDidEndDecelerating: (() -&gt; Void)?     public var onDidEndScrollingAnimation: (() -&gt; Void)?     public var onReorderIndexes: (((Int, Int)) -&gt; Void)?     public var onWillBeginReorder: ((IndexPath) -&gt; Void)?     public var onReorderEnter: (() -&gt; Void)?     public var onReorderExit: (() -&gt; Void)?      internal func subscribe(_ subscriber: AnyObject, onResize: @escaping ResizeCallback)     internal func unsubscribe(fromResize subscriber: AnyObject)     internal func subscribe(_ subscriber: AnyObject, onReady: @escaping ReadyCallback)     internal func unsubscribe(fromReady subscriber: AnyObject)      internal weak var collectionView: UICollectionView?      public internal(set) var items: [Model] { get set }      public func setup(collectionView: UICollectionView)      public func setHeader(_ model: ListHeaderView.Model)      public subscript(index: Int) -&gt; Model? { get }      public func reload(items: [Model], needsRedraw: Bool = true)      public func insertItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func appendItem(_ item: Model, allowDynamicModification: Bool = true)     public func deleteItem(at index: Int, allowDynamicModification: Bool = true)     public func deleteItemsIfNeeded(at range: PartialRangeFrom&lt;Int&gt;)     public func deleteItems(at indexes: [Int], allowDynamicModification: Bool = true)     public func updateItem(_ item: Model, at index: Int, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at range: PartialRangeFrom&lt;Int&gt;, allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [Model], at indexes: [Int], allowDynamicModification: Bool = true)     public func reloadItems(_ newItems: [(index: Int, element: Model)], allowDynamicModification: Bool = true)     public func moveItem(at index: Int, to newIndex: Int)      public func performBatchUpdates(updates: @escaping (ListAdapter) -&gt; Void, completion: ((Bool) -&gt; Void)?)     public func performBatchUpdates(updates: () -&gt; Void, completion: ((Bool) -&gt; Void)?)     }  public typealias ListAdapterCellConstraints = UICollectionViewCell &amp; RegistrableView &amp; AnimatedConfigurableView public typealias VerticalListAdapterCellConstraints = ListAdapterCellConstraints &amp; HeightMeasurableView public typealias HorizontalListAdapterCellConstraints = ListAdapterCellConstraints &amp; WidthMeasurableView <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f.<\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0434\u0451\u0442 \u0431\u043b\u043e\u043a typealias&#8217;\u043e\u0432 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b.<\/p>\n<p>DragAndDropStyle \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>headerModel &#8212; \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/p>\n<p>spacing &#8212; \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0451\u0442 \u0431\u043b\u043e\u043a \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 onReady \u0438 onResize \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u0442\u0430\u043b\u0430 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u0440\u0430\u0431\u043e\u0442\u0435, \u0438 \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u0437-\u0437\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>collectionView, setup(collectionView:) &#8212; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0435\u0451 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438<\/p>\n<p>items &#8212; \u043d\u0430\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<p>setHeader &#8212; \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/p>\n<p>itemSizeCacher &#8212; \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u0435\u0444\u043e\u043b\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"swift\">final class DefaultItemSizeCacher: UICollectionItemSizeCaching {          private var sizeCache: [IndexPath: CGSize] = [:]          func itemSize(cachedAt indexPath: IndexPath) -&gt; CGSize? {         sizeCache[indexPath]     }          func cache(itemSize: CGSize, at indexPath: IndexPath) {         sizeCache[indexPath] = itemSize     }          func invalidateItemSizeCache(at indexPath: IndexPath) {         sizeCache[indexPath] = nil     }          func invalidate() {         sizeCache = [:]     }      } <\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u044b \u043f\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0435\u043a \u043f\u043e \u043e\u0441\u0438.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>A<\/h><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-321423","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321423"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321423\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}