{"id":341080,"date":"2022-11-10T15:00:29","date_gmt":"2022-11-10T15:00:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341080"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341080","title":{"rendered":"<span>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c tableHeaderView \u0438 viewForHeaderInSection \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043b\u0435\u0442\u043d\u0435\u0439 \u043a\u0430\u0444\u0435\u0448\u043a\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c tableHeaderView \u0438 viewForHeaderInSection<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8bd\/58d\/a26\/8bd58da262ebe23ce8c57e15d91112f0.png\" width=\"1290\" height=\"2796\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8bd\/58d\/a26\/8bd58da262ebe23ce8c57e15d91112f0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c tableHeaderView \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0438\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0435 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 <br \/>\u041d\u0438\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f viewForHeaderInSection \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f<br \/>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0438\u0436\u0435 \u043f\u043e \u0442\u043e\u0432\u0430\u0440\u0430\u043c \u0431\u0430\u043d\u0435\u0440\u044b \u0443\u0445\u043e\u0434\u044f\u0442 \u0437\u0430 view \u0430 \u043d\u0430\u0448 \u0445\u0435\u0434\u0435\u0440 \u0441  \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u0438\u043f\u0430\u0435\u0442 \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u044d\u043a\u0440\u0430\u043d\u0430<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/943\/751\/fd8\/943751fd8fe9cbbdd5b7db43dc5324db.png\" width=\"448\" height=\"278\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/943\/751\/fd8\/943751fd8fe9cbbdd5b7db43dc5324db.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c \u043c\u044b \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0430\u043d\u043d\u0435\u0440\u0430 \u0438 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b UIView \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u043d\u0430\u0448 \u0431\u0430\u043d\u043d\u0435\u0440 \u043d\u0430\u0432\u0435\u0440\u0445 tableView \u0442\u0440\u0435\u0431\u0443\u0435\u0442 UIView<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6a0\/afd\/694\/6a0afd694afa37604aa9d72d288521a6.png\" width=\"495\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6a0\/afd\/694\/6a0afd694afa37604aa9d72d288521a6.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"swift\">final class BannersView: UIView {          private var banners = [String]()          private lazy var collectionView: UICollectionView = {         let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCompositionalLayout())                  collectionView.dataSource = self         collectionView.register(BannersCell.self, forCellWithReuseIdentifier: BannersCell.reuseID)         collectionView.backgroundColor = .systemBackground                  return collectionView     }()          override init(frame: CGRect) {         super.init(frame: frame)         self.setupViews()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func update(bannersString: [String]) {         banners = bannersString         collectionView.reloadData()         print(bannersString)     }          private func setupViews() {         addSubview(collectionView)         collectionView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     }          private func createCompositionalLayout() -> UICollectionViewLayout {         return UICollectionViewCompositionalLayout(section: createPromotionsView())     }          private func createPromotionsView()  -> NSCollectionLayoutSection {                  let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                               heightDimension: .fractionalHeight(1.0))         let item = NSCollectionLayoutItem(layoutSize: itemSize)         item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16)                  let rowHeight = NSCollectionLayoutDimension.fractionalHeight(1)         let rowSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.8),                                              heightDimension: rowHeight)         let row = NSCollectionLayoutGroup.horizontal(layoutSize: rowSize, subitems: [item])                  let section = NSCollectionLayoutSection(group: row)         section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 0)                  section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary                           return section     } }   extension BannersView: UICollectionViewDataSource {          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         print(banners)         return banners.count     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         guard let cell: BannersCell = collectionView.dequeueReusableCell(withReuseIdentifier: BannersCell.reuseID, for: indexPath) as? BannersCell else { return UICollectionViewCell()}                  print(banners)         let banner = banners[indexPath.row]         cell.configure(string: banner)                  return cell     } }<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a  \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 UIView \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 collectionView. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 update \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0431\u0430\u043d\u0435\u0440\u0430\u043c\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u044f\u0447\u0435\u0439\u043a\u0438  <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e84\/8b3\/2ae\/e848b32ae1ceaa4557a1a46b2abc751a.png\" width=\"418\" height=\"110\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e84\/8b3\/2ae\/e848b32ae1ceaa4557a1a46b2abc751a.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d04\/591\/f7f\/d04591f7f6a5a43398375ca5830d1867.png\" width=\"941\" height=\"351\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d04\/591\/f7f\/d04591f7f6a5a43398375ca5830d1867.png\"\/><figcaption><\/figcaption><\/figure>\n<p>CollectionView \u0433\u043e\u0442\u043e\u0432 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 BannersCell: UICollectionViewCell \u0438 \u0434\u043e\u0431\u043e\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e imageView <\/p>\n<pre><code class=\"swift\">import UIKit import SnapKit  final class BannersCell: UICollectionViewCell {          static let reuseID = \"BannersCell\"          private let imageView: UIImageView = {         let image = UIImageView()                  image.image = UIImage(named: \"banner1\")         image.contentMode = .center         image.contentMode = .scaleAspectFill                  return image     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupView()              }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func configure(string: String) {                  imageView.image = UIImage(named: string)     }          private func setupView() {                  backgroundColor = .systemBackground                           imageView.clipsToBounds = true         imageView.layer.cornerRadius = 10                           addSubview(imageView)         imageView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d7\/a1c\/932\/0d7a1c9327fbc7e383b80c388f8050d8.png\" width=\"480\" height=\"91\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d7\/a1c\/932\/0d7a1c9327fbc7e383b80c388f8050d8.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042f\u0447\u0435\u0439\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b collectionView \u0433\u043e\u0442\u043e\u0432 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b &#171;<strong>class<\/strong> MenuVC: UIViewController&#187;<\/p>\n<pre><code class=\"swift\">import UIKit  class MenuVC: UIViewController {          private let productsAPI = ProductsAPI()     private var products: [Products] = []          \/\/MARK: - TableView     private lazy var tableView: UITableView = {         let tableView = UITableView()                  tableView.register(ProductCell.self, forCellReuseIdentifier: ProductCell.reuseID)         tableView.dataSource = self         tableView.delegate = self         tableView.tableHeaderView = bannerHeaderView         tableView.separatorStyle = .none                  return tableView     }()          lazy var bannerHeaderView: BannersView = {         let width = UIView.screenWidth         let height = width * 0.3         let bannerView = BannersView(frame: CGRect(x: 0, y: 0, width: width, height: height))         return bannerView     }()          override func viewDidLoad() {         super.viewDidLoad()                  setupViews()         fetchProducts()     }          override func viewWillLayoutSubviews() {         super.viewWillLayoutSubviews()         tableView.rowHeight = view.bounds.height \/ 5     }          private func fetchProducts() {         Task {             do {                 let result = try await productsAPI.fetchCollection() \/\/\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u0441\u0435\u0442\u044c                 products = result.items \/\/\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432                                  bannerHeaderView.update(bannersString: result.banners) \/\/\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0431\u0430\u043d\u0435\u0440\u043e\u0432 \u0432 \u0445\u0435\u0434\u0435\u0440                 tableView.reloadData()                              } catch {                 print(error)             }         }     }          private func setupViews(){         view.backgroundColor = .systemBackground                  view.addSubview(tableView)         tableView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     } }  extension MenuVC: UITableViewDataSource, UITableViewDelegate {          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return products.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         guard let cell = tableView.dequeueReusableCell(withIdentifier: ProductCell.reuseID, for: indexPath) as? ProductCell else { return UITableViewCell() }         let products = products[indexPath.row]                  cell.configure(model: products)                  return cell     } } <\/code><\/pre>\n<p>\u0418  \u0442\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c  <strong>private<\/strong> <strong>let<\/strong> productsAPI = ProductsAPI() \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u0442\u044c<br \/><strong>private<\/strong> <strong>var<\/strong> products: [Products] = [] \u043c\u0435\u0441\u0442\u043e \u043a\u0443\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u043e\u0442\u0432\u0435\u0442 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c\u0438<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 tableView \u0438 bannerHeaderView. \u041c\u044b \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0448 tableView \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0445\u0435\u0434\u0435\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u043c tableView.tableHeaderView   <br \/>headerView \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0438\u0436\u0435 \u0437\u0430\u0434\u0430\u0432 \u0435\u043c\u0443 \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0448\u0438\u0440\u0438\u043d\u0443<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e4d\/7ac\/344\/e4d7ac344081e153df3ed2626ab38dde.png\" width=\"819\" height=\"331\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e4d\/7ac\/344\/e4d7ac344081e153df3ed2626ab38dde.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0441\u0435\u0442\u044c \u0438 \u043f\u0440\u043e\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448 bannerheaderView<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bfb\/7ed\/ab7\/bfb7edab71528d025dd67e110063306d.png\" width=\"827\" height=\"253\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bfb\/7ed\/ab7\/bfb7edab71528d025dd67e110063306d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430<\/p>\n<pre><code class=\"json\">{   \"items\":[     {       \"id\":0,       \"name\":\"\u041b\u0430\u0442\u0442\u0435\",       \"category\":\"coffee\",       \"description\":\"1\/4 \u0432\u0437\u0431\u0438\u0442\u043e\u0439 \u043c\u043e\u043b\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u043d\u044b, 2\/4 \u0433\u043e\u0440\u044f\u0447\u0435\u0433\u043e \u043c\u043e\u043b\u043e\u043a\u0430, 1\/4 \u044d\u0441\u043f\u0440\u0435\u0441\u0441\u043e\",       \"image\":\"latte\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":150     },     {       \"id\":1,       \"name\":\"\u041a\u0430\u043f\u0443\u0447\u0438\u043d\u043e\",       \"category\":\"ice coffe\",       \"description\":\"1\/3 \u0432\u0437\u0431\u0438\u0442\u043e\u0439 \u043c\u043e\u043b\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u043d\u044b, 1\/3 \u0433\u043e\u0440\u044f\u0447\u0435\u0433\u043e \u043c\u043e\u043b\u043e\u043a\u0430, 1\/3 \u044d\u0441\u043f\u0440\u0435\u0441\u0441\u043e\",       \"image\":\"cappuccino\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":300     },     {       \"id\":2,       \"name\":\"\u041f\u0438\u0446\u0446\u0430\",       \"category\":\"pizza\",       \"description\":\"\u0412\u0435\u0442\u0447\u0438\u043d\u0430, \u0448\u0430\u043c\u043f\u0438\u043d\u044c\u043e\u043d\u044b, \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u043c\u043e\u0446\u0430\u0440\u0435\u043b\u043b\u044b, \u0442\u043e\u043c\u0430\u0442\u043d\u044b\u0439 \u0441\u043e\u0443\u0441\",       \"image\":\"pizza\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":2500     }   ],   \"categories\":[\"Coffee\", \"Non Coffee\", \"Pastry\", \"Special\"],   \"banners\":[\"banner1\",\"banner2\"] \/\/\u041d\u0410\u0428\u0418 \u0411\u0410\u041d\u041d\u0415\u0420\u042b }<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/746\/c0b\/bc0\/746c0bbc03d685834fd7c88699caebde.png\" width=\"1290\" height=\"2796\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/746\/c0b\/bc0\/746c0bbc03d685834fd7c88699caebde.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0430\u0448\u0438\u043c\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432! \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 CategoriesView \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434 UITableViewHeaderFooterView \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c collectionView \u0438 \u0432\u0441\u044f \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"swift\">import UIKit  final class CategoriesView: UITableViewHeaderFooterView {          private var categories: [String]          lazy var collectionView: UICollectionView = {         let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCompositionalLayout())                  collectionView.dataSource = self         collectionView.delegate = self         collectionView.register(CategoryCell.self, forCellWithReuseIdentifier: CategoryCell.reuseID)         collectionView.backgroundColor = .systemBackground                  return collectionView     }()     init(categories: [String]) {         self.categories = categories         super.init(reuseIdentifier: CategoryCell.reuseID)         self.setupViews()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          private func setupViews() {         addSubview(collectionView)         collectionView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     }          private func createCompositionalLayout() -> UICollectionViewLayout {         return UICollectionViewCompositionalLayout(section: createButtonView())     }          private func createButtonView() -> NSCollectionLayoutSection {         let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                               heightDimension: .fractionalHeight(1.0))                  let item = NSCollectionLayoutItem(layoutSize: itemSize)         item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8)                  let rowHeight = NSCollectionLayoutDimension.fractionalHeight(1)         let rowSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.26), heightDimension: rowHeight)                  let row = NSCollectionLayoutGroup.horizontal(layoutSize: rowSize, subitems: [item])                  let section = NSCollectionLayoutSection(group: row)         section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 16, bottom: 10, trailing: 0)                  section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary                  return section     } }   extension CategoriesView: UICollectionViewDataSource {          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return categories.count     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell: CategoryCell = collectionView.dequeueReusableCell(withReuseIdentifier: CategoryCell.reuseID, for: indexPath) as! CategoryCell         cell.titleLabel.text = categories[indexPath.row]         return cell     }           }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/35b\/23b\/72d\/35b23b72dfb2d07da40ee88cedf916a9.png\" width=\"542\" height=\"88\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35b\/23b\/72d\/35b23b72dfb2d07da40ee88cedf916a9.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044f\u0447\u0435\u0439\u043a\u0438<\/p>\n<pre><code class=\"swift\">import UIKit import SnapKit  final class BannersCell: UICollectionViewCell {          static let reuseID = \"BannersCell\"          private let imageView: UIImageView = {         let image = UIImageView()                  image.image = UIImage(named: \"banner1\")         image.contentMode = .center         image.contentMode = .scaleAspectFill                  return image     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupView()              }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func configure(string: String) {                  imageView.image = UIImage(named: string)     }          private func setupView() {                  backgroundColor = .systemBackground                           imageView.clipsToBounds = true         imageView.layer.cornerRadius = 10                           addSubview(imageView)         imageView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     } }<\/code><\/pre>\n<p>\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/61a\/1b3\/0b0\/61a1b30b08d85de24c891197ab48beaa.png\" width=\"478\" height=\"76\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/61a\/1b3\/0b0\/61a1b30b08d85de24c891197ab48beaa.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0442\u0430\u043a \u0432\u0441\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0434\u043e\u043f\u043e\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043d\u0430 \u043d\u0430\u0448 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d <\/p>\n<p><\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0438\u0437 json<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0cd\/b74\/b6b\/0cdb74b6bed8cf1b7139eac0583da0c3.png\" width=\"728\" height=\"179\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0cd\/b74\/b6b\/0cdb74b6bed8cf1b7139eac0583da0c3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0432 viewForHeaderInSection \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 categoriesView  \u0438 \u0432 \u043d\u0430\u0448 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435. <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0445\u0435\u0434\u0435\u0440\u0430<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a96\/2de\/191\/a962de191b7a4ec2fa3bb942c1c61b06.png\" width=\"817\" height=\"186\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a96\/2de\/191\/a962de191b7a4ec2fa3bb942c1c61b06.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/38b\/bc7\/15e\/38bbc715ec078d420349ca6dc82e5b9d.png\" width=\"1290\" height=\"2796\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/38b\/bc7\/15e\/38bbc715ec078d420349ca6dc82e5b9d.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \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\/post\/698574\/\"> https:\/\/habr.com\/ru\/post\/698574\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043b\u0435\u0442\u043d\u0435\u0439 \u043a\u0430\u0444\u0435\u0448\u043a\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c tableHeaderView \u0438 viewForHeaderInSection<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c<\/p>\n<figure class=\"float full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c tableHeaderView \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0438\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0435 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 <br \/>\u041d\u0438\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f viewForHeaderInSection \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f<br \/>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0438\u0436\u0435 \u043f\u043e \u0442\u043e\u0432\u0430\u0440\u0430\u043c \u0431\u0430\u043d\u0435\u0440\u044b \u0443\u0445\u043e\u0434\u044f\u0442 \u0437\u0430 view \u0430 \u043d\u0430\u0448 \u0445\u0435\u0434\u0435\u0440 \u0441  \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u0438\u043f\u0430\u0435\u0442 \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u044d\u043a\u0440\u0430\u043d\u0430<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c \u043c\u044b \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0430\u043d\u043d\u0435\u0440\u0430 \u0438 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b UIView \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u043d\u0430\u0448 \u0431\u0430\u043d\u043d\u0435\u0440 \u043d\u0430\u0432\u0435\u0440\u0445 tableView \u0442\u0440\u0435\u0431\u0443\u0435\u0442 UIView<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"swift\">final class BannersView: UIView {          private var banners = [String]()          private lazy var collectionView: UICollectionView = {         let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCompositionalLayout())                  collectionView.dataSource = self         collectionView.register(BannersCell.self, forCellWithReuseIdentifier: BannersCell.reuseID)         collectionView.backgroundColor = .systemBackground                  return collectionView     }()          override init(frame: CGRect) {         super.init(frame: frame)         self.setupViews()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func update(bannersString: [String]) {         banners = bannersString         collectionView.reloadData()         print(bannersString)     }          private func setupViews() {         addSubview(collectionView)         collectionView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     }          private func createCompositionalLayout() -> UICollectionViewLayout {         return UICollectionViewCompositionalLayout(section: createPromotionsView())     }          private func createPromotionsView()  -> NSCollectionLayoutSection {                  let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                               heightDimension: .fractionalHeight(1.0))         let item = NSCollectionLayoutItem(layoutSize: itemSize)         item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16)                  let rowHeight = NSCollectionLayoutDimension.fractionalHeight(1)         let rowSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.8),                                              heightDimension: rowHeight)         let row = NSCollectionLayoutGroup.horizontal(layoutSize: rowSize, subitems: [item])                  let section = NSCollectionLayoutSection(group: row)         section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 0)                  section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary                           return section     } }   extension BannersView: UICollectionViewDataSource {          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         print(banners)         return banners.count     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         guard let cell: BannersCell = collectionView.dequeueReusableCell(withReuseIdentifier: BannersCell.reuseID, for: indexPath) as? BannersCell else { return UICollectionViewCell()}                  print(banners)         let banner = banners[indexPath.row]         cell.configure(string: banner)                  return cell     } }<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a  \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 UIView \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 collectionView. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 update \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0431\u0430\u043d\u0435\u0440\u0430\u043c\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u044f\u0447\u0435\u0439\u043a\u0438  <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>CollectionView \u0433\u043e\u0442\u043e\u0432 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 BannersCell: UICollectionViewCell \u0438 \u0434\u043e\u0431\u043e\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e imageView <\/p>\n<pre><code class=\"swift\">import UIKit import SnapKit  final class BannersCell: UICollectionViewCell {          static let reuseID = \"BannersCell\"          private let imageView: UIImageView = {         let image = UIImageView()                  image.image = UIImage(named: \"banner1\")         image.contentMode = .center         image.contentMode = .scaleAspectFill                  return image     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupView()              }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func configure(string: String) {                  imageView.image = UIImage(named: string)     }          private func setupView() {                  backgroundColor = .systemBackground                           imageView.clipsToBounds = true         imageView.layer.cornerRadius = 10                           addSubview(imageView)         imageView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u042f\u0447\u0435\u0439\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b collectionView \u0433\u043e\u0442\u043e\u0432 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b &#171;<strong>class<\/strong> MenuVC: UIViewController&#187;<\/p>\n<pre><code class=\"swift\">import UIKit  class MenuVC: UIViewController {          private let productsAPI = ProductsAPI()     private var products: [Products] = []          \/\/MARK: - TableView     private lazy var tableView: UITableView = {         let tableView = UITableView()                  tableView.register(ProductCell.self, forCellReuseIdentifier: ProductCell.reuseID)         tableView.dataSource = self         tableView.delegate = self         tableView.tableHeaderView = bannerHeaderView         tableView.separatorStyle = .none                  return tableView     }()          lazy var bannerHeaderView: BannersView = {         let width = UIView.screenWidth         let height = width * 0.3         let bannerView = BannersView(frame: CGRect(x: 0, y: 0, width: width, height: height))         return bannerView     }()          override func viewDidLoad() {         super.viewDidLoad()                  setupViews()         fetchProducts()     }          override func viewWillLayoutSubviews() {         super.viewWillLayoutSubviews()         tableView.rowHeight = view.bounds.height \/ 5     }          private func fetchProducts() {         Task {             do {                 let result = try await productsAPI.fetchCollection() \/\/\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u0441\u0435\u0442\u044c                 products = result.items \/\/\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432                                  bannerHeaderView.update(bannersString: result.banners) \/\/\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0431\u0430\u043d\u0435\u0440\u043e\u0432 \u0432 \u0445\u0435\u0434\u0435\u0440                 tableView.reloadData()                              } catch {                 print(error)             }         }     }          private func setupViews(){         view.backgroundColor = .systemBackground                  view.addSubview(tableView)         tableView.snp.makeConstraints { make in             make.edges.equalToSuperview()         }     } }  extension MenuVC: UITableViewDataSource, UITableViewDelegate {          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return products.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         guard let cell = tableView.dequeueReusableCell(withIdentifier: ProductCell.reuseID, for: indexPath) as? ProductCell else { return UITableViewCell() }         let products = products[indexPath.row]                  cell.configure(model: products)                  return cell     } } <\/code><\/pre>\n<p>\u0418  \u0442\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c  <strong>private<\/strong> <strong>let<\/strong> productsAPI = ProductsAPI() \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u0442\u044c<br \/><strong>private<\/strong> <strong>var<\/strong> products: [Products] = [] \u043c\u0435\u0441\u0442\u043e \u043a\u0443\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u043e\u0442\u0432\u0435\u0442 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c\u0438<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 tableView \u0438 bannerHeaderView. \u041c\u044b \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0448 tableView \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0445\u0435\u0434\u0435\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u043c tableView.tableHeaderView   <br \/>headerView \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0438\u0436\u0435 \u0437\u0430\u0434\u0430\u0432 \u0435\u043c\u0443 \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0448\u0438\u0440\u0438\u043d\u0443<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0441\u0435\u0442\u044c \u0438 \u043f\u0440\u043e\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448 bannerheaderView<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430<\/p>\n<pre><code class=\"json\">{   \"items\":[     {       \"id\":0,       \"name\":\"\u041b\u0430\u0442\u0442\u0435\",       \"category\":\"coffee\",       \"description\":\"1\/4 \u0432\u0437\u0431\u0438\u0442\u043e\u0439 \u043c\u043e\u043b\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u043d\u044b, 2\/4 \u0433\u043e\u0440\u044f\u0447\u0435\u0433\u043e \u043c\u043e\u043b\u043e\u043a\u0430, 1\/4 \u044d\u0441\u043f\u0440\u0435\u0441\u0441\u043e\",       \"image\":\"latte\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":150     },     {       \"id\":1,       \"name\":\"\u041a\u0430\u043f\u0443\u0447\u0438\u043d\u043e\",       \"category\":\"ice coffe\",       \"description\":\"1\/3 \u0432\u0437\u0431\u0438\u0442\u043e\u0439 \u043c\u043e\u043b\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u043d\u044b, 1\/3 \u0433\u043e\u0440\u044f\u0447\u0435\u0433\u043e \u043c\u043e\u043b\u043e\u043a\u0430, 1\/3 \u044d\u0441\u043f\u0440\u0435\u0441\u0441\u043e\",       \"image\":\"cappuccino\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":300     },     {       \"id\":2,       \"name\":\"\u041f\u0438\u0446\u0446\u0430\",       \"category\":\"pizza\",       \"description\":\"\u0412\u0435\u0442\u0447\u0438\u043d\u0430, \u0448\u0430\u043c\u043f\u0438\u043d\u044c\u043e\u043d\u044b, \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u043c\u043e\u0446\u0430\u0440\u0435\u043b\u043b\u044b, \u0442\u043e\u043c\u0430\u0442\u043d\u044b\u0439 \u0441\u043e\u0443\u0441\",       \"image\":\"pizza\",       \"cinnamon\":false,       \"sugar\":false,       \"variant\":\"hot\",       \"size\":\"Regular\",       \"price\":2500     }   ],   \"categories\":[\"Coffee\", \"Non Coffee\", \"Pastry\", \"Special\"],   \"banners\":[\"banner1\",\"banner2\"] \/\/\u041d\u0410\u0428\u0418 \u0411\u0410\u041d\u041d\u0415\u0420\u042b }<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"float full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0430\u0448\u0438\u043c\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432! \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 CategoriesView \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434 UITableViewHeaderFooterView \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c collectionView \u0438 \u0432\u0441\u044f \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"swift\">import UIKit  final class CategoriesView: UITableViewHeaderFooterView {          private var categories: [String]          lazy var collectionView: UICollectionView = {         let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCompositionalLayout())                  collectionView.dataSource = self         collectionView.delegate = self         collectionView.register(CategoryCell.self, forCellWithReuseIdentifier: CategoryCell.reuseID)         collectionView.backgroundColor = .systemBackground                  return collectionView     }()     init(categories: [String]) {         self.categories = categories<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/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-341080","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341080","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=341080"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341080\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}