{"id":331773,"date":"2022-04-11T09:00:47","date_gmt":"2022-04-11T09:00:47","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=331773"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=331773","title":{"rendered":"<span>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 Diffable data source \u0438 table views \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c UIKit<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d7d\/cb5\/80b\/d7dcb580bc7e9bcb337e6a5b2aca7c46.png\" alt=\"\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e dffable data source\" title=\"\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e dffable data source\" width=\"1560\" height=\"880\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d7d\/cb5\/80b\/d7dcb580bc7e9bcb337e6a5b2aca7c46.png\"\/><figcaption>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e dffable data source<\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0440\u0430\u043d, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>Diffable data source<\/code> \u0438 table view.<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 <strong>Xcode<\/strong> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <strong>storyboard<\/strong>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <strong>UIKit<\/strong>.<\/p>\n<p>\u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/theswiftdev.com\/uitableview-tutorial-in-swift\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443<\/a>, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 UIKit, \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439, \u0442\u043e <a href=\"https:\/\/t.me\/+qll_YZ6_8bo2Njky\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435<\/a> \u044f \u043f\u0438\u0448\u0443 \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u0441\u0432\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 <strong>UITableView<\/strong> \u0438 <strong>UICollectionView<\/strong>. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <\/p>\n<pre><code class=\"swift\">import UIKit  extension UITableViewCell {          static var reuseIdentifier: String {         String(describing: self)     }      var reuseIdentifier: String {         type(of: self).reuseIdentifier     } }  extension UITableView {              func register&lt;T: UITableViewCell>(_ type: T.Type) {         register(T.self, forCellReuseIdentifier: T.reuseIdentifier)     }      func reuse&lt;T: UITableViewCell>(_ type: T.Type, _ indexPath: IndexPath) -> T {         dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T     } }<\/code><\/pre>\n<p>\u042f \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f <code>UITableView<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0441\u0451 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>initialize<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435.<\/p>\n<pre><code class=\"swift\">import UIKit  open class TableView: UITableView {      public init(style: UITableView.Style = .plain) {         super.init(frame: .zero, style: style)                  initialize()     }      @available(*, unavailable)     required public init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          open func initialize() {         translatesAutoresizingMaskIntoConstraints = false         allowsMultipleSelection = true     }          func layoutConstraints(in view: UIView) -> [NSLayoutConstraint] {         [             topAnchor.constraint(equalTo: view.topAnchor),             bottomAnchor.constraint(equalTo: view.bottomAnchor),             leadingAnchor.constraint(equalTo: view.leadingAnchor),             trailingAnchor.constraint(equalTo: view.trailingAnchor),         ]     } }<\/code><\/pre>\n<p>\u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0440\u0430\u043d \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0441 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"swift\">import UIKit  public extension UITableView {          func select(_ indexPaths: [IndexPath],                 animated: Bool = true,                 scrollPosition: UITableView.ScrollPosition = .none) {         for indexPath in indexPaths {             selectRow(at: indexPath, animated: animated, scrollPosition: scrollPosition)         }     }           func deselect(_ indexPaths: [IndexPath], animated: Bool = true) {         for indexPath in indexPaths {             deselectRow(at: indexPath, animated: animated)         }     }          func deselectAll(animated: Bool = true) {         deselect(indexPathsForSelectedRows ?? [], animated: animated)     }      func deselectAllInSection(except indexPath: IndexPath) {         let indexPathsToDeselect = (indexPathsForSelectedRows ?? []).filter {             $0.section == indexPath.section &amp;&amp; $0.row != indexPath.row         }         deselect(indexPathsToDeselect)     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 API \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044f\u0447\u0435\u0435\u043a, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"swift\">import Foundation  protocol CustomCellModel {     var text: String { get }     var secondaryText: String? { get } }  extension CustomCellModel {     var secondaryText: String? { nil } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>CustomCell<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0451 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u042d\u0442\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0432\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u044f\u0447\u0435\u0439\u043a\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0437\u043d\u0430\u0447\u043e\u043a \u0433\u0430\u043b\u043e\u0447\u043a\u0438, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u0440\u0443\u0433. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043b\u0435\u0439\u0431\u043b\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<pre><code class=\"swift\">import UIKit  class CustomCell: UITableViewCell {      var model: CustomCellModel?      override func updateConfiguration(using state: UICellConfigurationState) {         super.updateConfiguration(using: state)                  var contentConfig = defaultContentConfiguration().updated(for: state)         contentConfig.text = model?.text         contentConfig.secondaryText = model?.secondaryText                  contentConfig.imageProperties.tintColor = .systemBlue         contentConfig.image = UIImage(systemName: \"circle\")          if state.isHighlighted || state.isSelected {             contentConfig.image = UIImage(systemName: \"checkmark.circle.fill\")         }         contentConfiguration = contentConfig     } }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <strong>ViewController<\/strong> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c storyboard, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>init(coder:)<\/code>, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>init<\/code>.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u044f \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0435\u0440\u043d\u0443\u043b \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u043d\u0443\u0442\u0440\u0438 <code>navigation controller<\/code>, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>large style<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u0432\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController {          var tableView: TableView          required init?(coder: NSCoder) {         self.tableView = TableView(style: .insetGrouped)          super.init(coder: coder)     }          override func loadView() {         super.loadView()                  view.addSubview(tableView)          NSLayoutConstraint.activate(tableView.layoutConstraints(in: view))     }      override func viewDidLoad() {         super.viewDidLoad()                  title = \"Table view\"         navigationController?.navigationBar.prefersLargeTitles = true          tableView.register(CustomCell.self)         tableView.delegate = self      }          override func viewDidAppear(_ animated: Bool) {         super.viewDidAppear(animated)                  reload()     }          func reload() {         \/\/\/ coming soon...     }  }  extension ViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         \/\/\/ coming soon...     }      func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {         \/\/\/ coming soon...     } }<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 <code>diffable data source<\/code>. \u041f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h3>Diffable data source<\/h3>\n<p>\u042f \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 <code>diffable data source<\/code>, \u043d\u043e \u044d\u0442\u043e \u0431\u044b\u043b \u0443\u0447\u0435\u0431\u043d\u0438\u043a \u043f\u043e <a href=\"https:\/\/theswiftdev.com\/how-to-create-reusable-views-for-modern-collection-views\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439<\/a>. <strong>Diffable data source<\/strong> &#8212; \u044d\u0442\u043e \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a view. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/uitableviewdiffabledatasource\" rel=\"noopener noreferrer nofollow\">UITableViewDiffableDataSource<\/a> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u042d\u0442\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <code>indexPath<\/code>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0434\u0432\u0435 \u0441\u0435\u043a\u0446\u0438\u0438, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u2014 \u043c\u0443\u043b\u044c\u0442\u0438\u0432\u044b\u0431\u043e\u0440\u0430 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0431\u0443\u043a\u0432\u0430\u043c\u0438 \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u0412\u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0435\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"swift\">enum NumberOption: String, CaseIterable {     case one     case two     case three }  extension NumberOption: CustomCellModel {       var text: String { rawValue } }  enum LetterOption: String, CaseIterable {     case a     case b     case c     case d }  extension LetterOption: CustomCellModel {       var text: String { rawValue } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u044d\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <code>diffabe data source<\/code>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c <code>indexPaths<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>Hashable<\/code> \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0441\u0435\u043a\u0446\u0438\u0439. \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0435 \u0441\u0435\u043a\u0446\u0438\u0438, \u043e\u0434\u043d\u0430 \u0434\u043b\u044f \u0446\u0438\u0444\u0440, \u0434\u0440\u0443\u0433\u0430\u044f \u0434\u043b\u044f \u0431\u0443\u043a\u0432. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"swift\">enum Section: Hashable {     case numbers     case letters }  enum SectionItem: Hashable {     case number(NumberOption)     case letter(LetterOption) }  struct SectionData {     var key: Section     var values: [SectionItem] }<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u0432\u0435\u0434\u0435\u043c  <code>SectionData<\/code>, \u0441 \u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0441\u0435\u043a\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"swift\">final class DataSource: UITableViewDiffableDataSource&lt;Section, SectionItem> {          init(_ tableView: UITableView) {         super.init(tableView: tableView) { tableView, indexPath, itemIdentifier in             let cell = tableView.reuse(CustomCell.self, indexPath)             cell.selectionStyle = .none             switch itemIdentifier {             case .number(let model):                 cell.model = model             case .letter(let model):                 cell.model = model             }             return cell         }     }          override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {         let id = sectionIdentifier(for: section)         switch id {         case .numbers:             return \"Pick a number\"         case .letters:             return \"Pick some letters\"         default:             return nil         }     }      func reload(_ data: [SectionData], animated: Bool = true) {         var snapshot = snapshot()         snapshot.deleteAllItems()         for item in data {             snapshot.appendSections([item.key])             snapshot.appendItems(item.values, toSection: item.key)         }         apply(snapshot, animatingDifferences: animated)     } }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 init \u0434\u043b\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  <code>cell provider<\/code> \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0448\u0438\u0445 \u044f\u0447\u0435\u0435\u043a \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c.<\/p>\n<p> \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>SectionItem<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u043d\u0430\u0437\u0430\u0434. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c (<code>switch<\/code>), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 <code>CustomCellModel<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>cell.model<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>titleForHeaderInSection<\/code>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043b\u0435\u0439\u0431\u043b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0435\u0433\u043e \u0434\u043b\u044f \u0440\u0435\u043b\u043e\u0430\u0434\u0430 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0441\u0435\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController {          var tableView: TableView     var dataSource: DataSource          required init?(coder: NSCoder) {         self.tableView = TableView(style: .insetGrouped)         self.dataSource = DataSource(tableView)          super.init(coder: coder)     }          override func loadView() {         super.loadView()                  view.addSubview(tableView)          NSLayoutConstraint.activate(tableView.layoutConstraints(in: view))     }      override func viewDidLoad() {         super.viewDidLoad()                  title = \"Table view\"         navigationController?.navigationBar.prefersLargeTitles = true          tableView.register(CustomCell.self)         tableView.delegate = self      }          override func viewDidAppear(_ animated: Bool) {         super.viewDidAppear(animated)                  reload()     }          func reload() {         dataSource.reload([             .init(key: .numbers, values: NumberOption.allCases.map { .number($0) }),             .init(key: .letters, values: LetterOption.allCases.map { .letter($0) }),         ])     }  }  extension ViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         \/\/ coming soon...     }      func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {         \/\/ coming soon...     } }<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432\u0438\u0434 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431\u0435 \u0441\u0435\u043a\u0446\u0438\u0438. \u0414\u0430\u0436\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>indexPathsForSelectedRows<\/code>, \u043d\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0435\u043a\u0446\u0438\u0438. <\/p>\n<pre><code class=\"swift\">struct SelectionOptions&lt;T: Hashable> {      var values: [T]     var selectedValues: [T]     var multipleSelection: Bool      init(_ values: [T], selected: [T] = [], multiple: Bool = false) {         self.values = values         self.selectedValues = selected         self.multipleSelection = multiple     }      mutating func toggle(_ value: T) {         guard multipleSelection else {             selectedValues = [value]             return         }         if selectedValues.contains(value) {             selectedValues = selectedValues.filter { $0 != value }         }         else {             selectedValues.append(value)         }     } }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0449\u0435\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <code>UITableViewDiffableDataSource<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 <code>indexPaths<\/code>, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 view.<\/p>\n<pre><code class=\"swift\">import UIKit  extension UITableViewDiffableDataSource {      func selectedIndexPaths&lt;T: Hashable>(_ selection: SelectionOptions&lt;T>,                                          _ transform: (T) -> ItemIdentifierType) ->  [IndexPath] {         selection.values             .filter { selection.selectedValues.contains($0) }             .map { transform($0) }             .compactMap { indexPath(for: $0) }     } }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e &#8212; \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 <code>didSelectRowAt<\/code> \u0438 <code>didDeselectRowAt<\/code>.<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController {          var tableView: TableView     var dataSource: DataSource          var singleOptions = SelectionOptions&lt;NumberOption>(NumberOption.allCases, selected: [.two])     var multipleOptions = SelectionOptions&lt;LetterOption>(LetterOption.allCases, selected: [.a, .c], multiple: true)      required init?(coder: NSCoder) {         self.tableView = TableView(style: .insetGrouped)         self.dataSource = DataSource(tableView)          super.init(coder: coder)     }          override func loadView() {         super.loadView()                  view.addSubview(tableView)          NSLayoutConstraint.activate(tableView.layoutConstraints(in: view))     }      override func viewDidLoad() {         super.viewDidLoad()                  title = \"Table view\"         navigationController?.navigationBar.prefersLargeTitles = true          tableView.register(CustomCell.self)         tableView.delegate = self      }          override func viewDidAppear(_ animated: Bool) {         super.viewDidAppear(animated)                  reload()     }          func reload() {         dataSource.reload([             .init(key: .numbers, values: singleOptions.values.map { .number($0) }),             .init(key: .letters, values: multipleOptions.values.map { .letter($0) }),         ])          tableView.select(dataSource.selectedIndexPaths(singleOptions) { .number($0) })         tableView.select(dataSource.selectedIndexPaths(multipleOptions) { .letter($0) })     }  }  extension ViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         guard let sectionId = dataSource.sectionIdentifier(for: indexPath.section) else {             return         }          switch sectionId {         case .numbers:             guard case let .number(model) = dataSource.itemIdentifier(for: indexPath) else {                 return             }             tableView.deselectAllInSection(except: indexPath)             singleOptions.toggle(model)             print(singleOptions.selectedValues)                      case .letters:             guard case let .letter(model) = dataSource.itemIdentifier(for: indexPath) else {                 return             }             multipleOptions.toggle(model)             print(multipleOptions.selectedValues)         }     }      func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {         guard let sectionId = dataSource.sectionIdentifier(for: indexPath.section) else {             return         }         switch sectionId {         case .numbers:             tableView.select([indexPath])         case .letters:             guard case let .letter(model) = dataSource.itemIdentifier(for: indexPath) else {                 return             }             multipleOptions.toggle(model)             print(multipleOptions.selectedValues)         }     } }<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u0432\u044b\u0431\u043e\u0440\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u044e \u0441 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u043c \u0438\u043b\u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u0441\u0435\u043b\u0435\u043a\u0442\u043e\u043c, \u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u0438 \u0432\u0435\u0449\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f <em>\u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438<\/em>, \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u043c\u0435\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e <code>SwiftUI<\/code>.<\/p>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0437 \u0432\u0430\u0441, \u043c\u043d\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f <code>UIKit<\/code>, \u0438 \u044f \u0440\u0430\u0434, \u0447\u0442\u043e Apple \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. <code>Diffable data source<\/code> &#8212; \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u044d\u043a\u0440\u0430\u043d\u044b.<\/p>\n<hr\/>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0439, \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/t.me\/+qll_YZ6_8bo2Njky\" rel=\"noopener noreferrer nofollow\">\u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435 \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435<\/a>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ly\/zj\/ec\/lyzjecwhl87so3d9jpcq17tirkm.png\" alt=\"\u041a\u0430\u043d\u0430\u043b \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435\" title=\"\u041a\u0430\u043d\u0430\u043b \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435\" width=\"959\" height=\"123\" data-src=\"https:\/\/habrastorage.org\/webt\/ly\/zj\/ec\/lyzjecwhl87so3d9jpcq17tirkm.png\"\/><figcaption>\u041a\u0430\u043d\u0430\u043b \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435<\/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\/660121\/\"> https:\/\/habr.com\/ru\/post\/660121\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e dffable data source<\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0440\u0430\u043d, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>Diffable data source<\/code> \u0438 table view.<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 <strong>Xcode<\/strong> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <strong>storyboard<\/strong>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <strong>UIKit<\/strong>.<\/p>\n<p>\u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/theswiftdev.com\/uitableview-tutorial-in-swift\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443<\/a>, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 UIKit, \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439, \u0442\u043e <a href=\"https:\/\/t.me\/+qll_YZ6_8bo2Njky\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435<\/a> \u044f \u043f\u0438\u0448\u0443 \u043e\u0431 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u0441\u0432\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 <strong>UITableView<\/strong> \u0438 <strong>UICollectionView<\/strong>. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <\/p>\n<pre><code class=\"swift\">import UIKit  extension UITableViewCell {          static var reuseIdentifier: String {         String(describing: self)     }      var reuseIdentifier: String {         type(of: self).reuseIdentifier     } }  extension UITableView {              func register&lt;T: UITableViewCell>(_ type: T.Type) {         register(T.self, forCellReuseIdentifier: T.reuseIdentifier)     }      func reuse&lt;T: UITableViewCell>(_ type: T.Type, _ indexPath: IndexPath) -> T {         dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T     } }<\/code><\/pre>\n<p>\u042f \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f <code>UITableView<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0441\u0451 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>initialize<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435.<\/p>\n<pre><code class=\"swift\">import UIKit  open class TableView: UITableView {      public init(style: UITableView.Style = .plain) {         super.init(frame: .zero, style: style)                  initialize()     }      @available(*, unavailable)     required public init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          open func initialize() {         translatesAutoresizingMaskIntoConstraints = false         allowsMultipleSelection = true     }          func layoutConstraints(in view: UIView) -> [NSLayoutConstraint] {         [             topAnchor.constraint(equalTo: view.topAnchor),             bottomAnchor.constraint(equalTo: view.bottomAnchor),             leadingAnchor.constraint(equalTo: view.leadingAnchor),             trailingAnchor.constraint(equalTo: view.trailingAnchor),         ]     } }<\/code><\/pre>\n<p>\u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0440\u0430\u043d \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0441 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"swift\">import UIKit  public extension UITableView {          func select(_ indexPaths: [IndexPath],                 animated: Bool = true,                 scrollPosition: UITableView.ScrollPosition = .none) {         for indexPath in indexPaths {             selectRow(at: indexPath, animated: animated, scrollPosition: scrollPosition)         }     }           func deselect(_ indexPaths: [IndexPath], animated: Bool = true) {         for indexPath in indexPaths {             deselectRow(at: indexPath, animated: animated)         }     }          func deselectAll(animated: Bool = true) {         deselect(indexPathsForSelectedRows ?? [], animated: animated)     }      func deselectAllInSection(except indexPath: IndexPath) {         let indexPathsToDeselect = (indexPathsForSelectedRows ?? []).filter {             $0.section == indexPath.section &amp;&amp; $0.row != indexPath.row         }         deselect(indexPathsToDeselect)     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 API \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044f\u0447\u0435\u0435\u043a, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"swift\">import Foundation  protocol CustomCellModel {     var text: String { get }     var secondaryText: String? { get } }  extension CustomCellModel {     var secondaryText: String? { nil } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>CustomCell<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0451 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u042d\u0442\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0432\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u044f\u0447\u0435\u0439\u043a\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0437\u043d\u0430\u0447\u043e\u043a \u0433\u0430\u043b\u043e\u0447\u043a\u0438, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u0440\u0443\u0433. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043b\u0435\u0439\u0431\u043b\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<pre><code class=\"swift\">import UIKit  class CustomCell: UITableViewCell {      var model: CustomCellModel?      override func updateConfiguration(using state: UICellConfigurationState) {         super.updateConfiguration(using: state)                  var contentConfig = defaultContentConfiguration().updated(for: state)         contentConfig.text = model?.text         contentConfig.secondaryText = model?.secondaryText                  contentConfig.imageProperties.tintColor = .systemBlue         contentConfig.image = UIImage(systemName: \"circle\")          if state.isHighlighted || state.isSelected {             contentConfig.image = UIImage(systemName: \"checkmark.circle.fill\")         }         contentConfiguration = contentConfig     } }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <strong>ViewController<\/strong> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c storyboard, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>init(coder:)<\/code>, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>init<\/code>.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u044f \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0435\u0440\u043d\u0443\u043b \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u043d\u0443\u0442\u0440\u0438 <code>navigation controller<\/code>, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>large style<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u0432\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController {          var tableView: TableView          required init?(coder: NSCoder) {         self.tableView = TableView(style: .insetGrouped)          super.init(coder: coder)     }          override func loadView() {         super.loadView()                  view.addSubview(tableView)          NSLayoutConstraint.activate(tableView.layoutConstraints(in: view))     }      override func viewDidLoad() {         super.viewDidLoad()                  title = \"Table view\"         navigationController?.navigationBar.prefersLargeTitles = true          tableView.register(CustomCell.self)         tableView.delegate = self      }          override func viewDidAppear(_ animated: Bool) {         super.viewDidAppear(animated)                  reload()     }          func reload() {         \/\/\/ coming soon...     }  }  extension ViewController: UITableViewDelegate {      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         \/\/\/ coming soon...     }      func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {         \/\/\/ coming soon...     } }<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 <code>diffable data source<\/code>. \u041f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h3>Diffable data source<\/h3>\n<p>\u042f \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 <code>diffable data source<\/code>, \u043d\u043e \u044d\u0442\u043e \u0431\u044b\u043b \u0443\u0447\u0435\u0431\u043d\u0438\u043a \u043f\u043e <a href=\"https:\/\/theswiftdev.com\/how-to-create-reusable-views-for-modern-collection-views\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439<\/a>. <strong>Diffable data source<\/strong> &#8212; \u044d\u0442\u043e \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0434\u0430\u0442\u0430\u0441\u043e\u0440\u0441, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a view. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/uitableviewdiffabledatasource\" rel=\"noopener noreferrer nofollow\">UITableViewDiffableDataSource<\/a> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u042d\u0442\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u044f\u0447\u0435\u0439\u043a\u0430\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <code>indexPath<\/code>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0434\u0432\u0435 \u0441\u0435\u043a\u0446\u0438\u0438, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u2014 \u043c\u0443\u043b\u044c\u0442\u0438\u0432\u044b\u0431\u043e\u0440\u0430 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0431\u0443\u043a\u0432\u0430\u043c\u0438 \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u0412\u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0435\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"swift\">enum NumberOption: String, CaseIterable {     case one     case two     case three }  extension NumberOption: CustomCellModel {       var text: String { rawValue } }  enum LetterOption: String, CaseIterable {     case a     case b     case c     case d }  extension LetterOption: CustomCellModel {       var text: String { rawValue } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u044d\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <code>diffabe data source<\/code>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c <code>indexPaths<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>Hashable<\/code> \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0441\u0435\u043a\u0446\u0438\u0439. \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0435 \u0441\u0435\u043a\u0446\u0438\u0438, \u043e\u0434\u043d\u0430 \u0434\u043b\u044f \u0446\u0438\u0444\u0440, \u0434\u0440\u0443\u0433\u0430\u044f \u0434\u043b\u044f \u0431\u0443\u043a\u0432. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"swift\">enum Section: Hashable {     case numbers     case letters }  enum SectionItem: Hashable {     case number(NumberOption)     case letter(LetterOption) }  struct SectionData {     var key: Section     var values: [SectionItem] }<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u0432\u0435\u0434\u0435\u043c  <code>SectionData<\/code>, \u0441 \u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0441\u0435\u043a\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"swift\">final class DataSource: UITableViewDiffableDataSource&lt;Section, SectionItem> {          init(_ tableView: UITableView) {         super.init(tableView: tableView) { tableView, indexPath, itemIdentifier in             let cell = tableView.reuse(CustomCell.self, indexPath)             cell.selectionStyle = .none             switch itemIdentifier {             case .number(let model):                 cell.model = model             case .letter(let model):                 cell.model = model             }             return cell         }     }          override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {         let id = sectionIdentifier(for: section)         switch id {         case .numbers:             return \"Pick a number\"         case .letters:             return \"Pick some letters\"         default:             return nil         }     }      func reload(_ data: [SectionData], animated: Bool = true) {         var snapshot = snapshot()         snapshot.deleteAllItems()         for item in data {             snapshot.appendSections([item.key])             snapshot.appendItems(item.values, toSection: item.key)         }         apply(snapshot, animatingDifferences: animated)     } }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 init \u0434\u043b\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  <code>cell provider<\/code> \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0448\u0438\u0445 \u044f\u0447\u0435\u0435\u043a \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c.<\/p>\n<p> \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>SectionItem<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e<\/p>\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-331773","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331773","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=331773"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331773\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}