<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Denys Telezhkin</title>
    <description>The latest articles on DEV Community by Denys Telezhkin (@dentelezhkin).</description>
    <link>https://dev.to/dentelezhkin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F553199%2F301ee48b-77be-4058-b5ff-6ee8b2615183.jpeg</url>
      <title>DEV Community: Denys Telezhkin</title>
      <link>https://dev.to/dentelezhkin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dentelezhkin"/>
    <language>en</language>
    <item>
      <title>What's new in DTTableView/CollectionViewManager 11</title>
      <dc:creator>Denys Telezhkin</dc:creator>
      <pubDate>Thu, 06 Oct 2022 12:46:51 +0000</pubDate>
      <link>https://dev.to/dentelezhkin/whats-new-in-dttableviewcollectionviewmanager-11-44co</link>
      <guid>https://dev.to/dentelezhkin/whats-new-in-dttableviewcollectionviewmanager-11-44co</guid>
      <description>&lt;p&gt;11.0 is a next major release of &lt;a href="https://github.com/DenTelezhkin/DTTableViewManager"&gt;DTTableViewManager&lt;/a&gt; and &lt;a href="https://github.com/DenTelezhkin/DTCollectionViewManager"&gt;DTCollectionViewManager&lt;/a&gt; frameworks, bringing not one, but two SwiftUI integrations, support for datasource prefetching, enhanced macCatalyst support, as well as updates for iOS 16 / tvOS 16 SDK.&lt;/p&gt;

&lt;h1&gt;
  
  
  Table of contents
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
Support for SwiftUI views in cells

&lt;ul&gt;
&lt;li&gt;iOS 13 and higher&lt;/li&gt;
&lt;li&gt;iOS 16 and higher&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Datasource prefetching&lt;/li&gt;
&lt;li&gt;Enhanced macCatalyst support&lt;/li&gt;
&lt;li&gt;Xcode 14 / iOS 16 / tvOS 16&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support for SwiftUI views in cells
&lt;/h2&gt;

&lt;p&gt;I strongly believe SwiftUI is a future of UI development on Apple platforms. Unfortunately, I also believe, that this future is not fully here yet. SwiftUI is very powerful, but has lots of issues, that require attention from Apple developers, as well as time in order to drop old OS releases like iOS 13 and macOS Catalina where SwiftUI is in very rough state. &lt;/p&gt;

&lt;p&gt;SwiftUI is also not a full replacement for all UIKit / AppKit components, as they have much more functionality than SwiftUI can support at this very moment. Those components include &lt;code&gt;UITableView&lt;/code&gt; and &lt;code&gt;UICollectionView&lt;/code&gt;. While being partially replaced by SwiftUI &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;LazyVStack&lt;/code&gt;, &lt;code&gt;LazyHStack&lt;/code&gt; and &lt;code&gt;LazyVGrid&lt;/code&gt; / &lt;code&gt;LazyHGrid&lt;/code&gt;, &lt;code&gt;UITableView&lt;/code&gt; and &lt;code&gt;UICollectionView&lt;/code&gt; in some places provide much more functionality and performance than their SwiftUI counterparts. However, where SwiftUI completely dominates, is in layout, which is much more powerful and simple than AutoLayout.&lt;/p&gt;

&lt;p&gt;So in DTTableViewManager 11, we are bridging two worlds, and taking best from both of them - SwiftUI view layout and UIKit performance and functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  iOS 13 and higher
&lt;/h3&gt;

&lt;p&gt;Apple officially introduced support for SwiftUI in table and collection view cells on iOS 16 with &lt;code&gt;UIHostingConfiguration&lt;/code&gt;, which is now supported by DTTableViewManager (read more about this below). However, for those of us (me included), who are not yet ready to jump to iOS 16 deployment target, DTTableView/CollectionViewManagers provide new methods to host SwiftUI in table and collection view cells on iOS 13 and higher:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerHostingCell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indexPath&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="kt"&gt;PostSwiftUIView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This integrations comes with some caveats, that you need to be aware of.&lt;/p&gt;

&lt;p&gt;First of all, this is not officially supported by Apple, which means that &lt;code&gt;UITableView&lt;/code&gt; and &lt;code&gt;UICollectionView&lt;/code&gt; will not know anything about what is hosted in the cells. This means, that you need to either provide estimated sizes for cells, or match the size of cells in UIKit with sizes you use in SwiftUI, otherwise layout systems will go to war with each other, producing unexpected results.&lt;/p&gt;

&lt;p&gt;Secondly, while in AppKit there is &lt;code&gt;NSHostingView&lt;/code&gt;, UIKit does not have UIHostingView, and needs to rely on &lt;code&gt;UIHostingController&lt;/code&gt; instead. This may come with some surprises, because &lt;code&gt;UIHostingController&lt;/code&gt; in some cases tries to avoid keyboard and adjust for safe area insets, which is obviously not needed in a view hosted in &lt;code&gt;UITableViewCell&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;While those issues are present not only in table and collection view cells (but actually anywhere you want to use &lt;code&gt;UIHostingController&lt;/code&gt;), we still need a way to work around those. To do that, you can use a custom subclass of &lt;code&gt;UIHostingController&lt;/code&gt;, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerHostingCell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="kt"&gt;PostSwiftUICell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nv"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mapping&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostingControllerMaker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;ControlledNavigationHostingController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;rootView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read about all customization options for SwiftUI configuration in a &lt;a href="https://github.com/DenTelezhkin/DTTableViewManager/blob/main/Documentation/SwiftUI.md"&gt;separate document&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In my experience, with some minor adjustments to &lt;code&gt;UIHostingController&lt;/code&gt; and cell sizing, SwiftUI views in cells seem to be working great, and I definitely recommend trying those.&lt;/p&gt;

&lt;h3&gt;
  
  
  iOS 16 and higher
&lt;/h3&gt;

&lt;p&gt;If you are ready to drop support for old OS-es now, DTTableViewManager now integrates with iOS 16 API - &lt;code&gt;UIHostingConfiguration&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerHostingConfiguration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indexPath&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="kt"&gt;UIHostingConfiguration&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;PostView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because this is officially supported way of integrating SwiftUI with table and collection view cells, I highly recommend watching &lt;a href="https://developer.apple.com/videos/play/wwdc2022/10072/"&gt;WWDC 2022 session video&lt;/a&gt; on this topic. &lt;/p&gt;

&lt;p&gt;All customization options for &lt;code&gt;UIHostingConfiguration&lt;/code&gt; are fully supported, for example you can customize margins for cell content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerHostingConfiguration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indexPath&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="kt"&gt;UIHostingConfiguration&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;PostView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;margins&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;horizontal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, you can also use &lt;code&gt;UICellConfigurationState&lt;/code&gt; of a cell by simply adding one additional parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;manager.registerHostingConfiguration(for: Post.self) { state, cell, post, indexPath in
    UIHostingConfiguration {
        PostView(post: post, isSelected: state.isSelected)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Datasource prefetching
&lt;/h2&gt;

&lt;p&gt;I'm quite late to the party of datasource prefetching, but better late, than never, right? :)&lt;/p&gt;

&lt;p&gt;Datasource prefetching is now supported with two additional event methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;PostCell&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mapping&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prefetch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indexPath&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; 
        &lt;span class="c1"&gt;// start prefetching for model&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cancelPrefetch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indexPath&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; 
        &lt;span class="c1"&gt;// cancel prefetching for model&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note, that while &lt;code&gt;UITableViewDataSourcePrefetching&lt;/code&gt; and &lt;code&gt;UICollectionViewDataSourcePrefetching&lt;/code&gt; call prefetching methods with array of indexPaths, DTTableViewManager and DTCollectionViewManager call prefetching events for a single data model, using forEach loop. This should make management of prefetching operations easier.&lt;/p&gt;

&lt;p&gt;If, however, you prefer receiving array of index paths, as with all delegate methods, you can absolutely do that by simply implementing &lt;code&gt;UITableViewDataSourcePrefetching&lt;/code&gt; methods on your &lt;code&gt;DTTableViewManageable&lt;/code&gt; instance (typically view controller with tableView, where you access DTTableViewManager).&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhanced macCatalyst support
&lt;/h2&gt;

&lt;p&gt;While macCatalyst was supported for a while, now instead of just building frameworks for macCatalyst, DTTableViewManager runs full iOS test suite on CI for both Xcode 13 and Xcode 14. &lt;/p&gt;

&lt;p&gt;This will make sure, that macCatalyst builds are not broken with future releases.&lt;/p&gt;

&lt;p&gt;Please note, that while iOS 16 was released with Xcode 14, macCatalyst 16 will be released with Xcode 14.1 along with macOS Ventura later this fall, so previously mentioned UIHostingConfiguration support is not available with macCatalyst and Xcode 14.0. &lt;/p&gt;

&lt;p&gt;If you want to test new functionality with macCatalyst - use Xcode 14.1 beta for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Xcode 14 and iOS 16 SDK
&lt;/h2&gt;

&lt;p&gt;As every year, DTTableViewManager and DTCollectionViewManager are adding support for new delegate methods, and deprecating events / delegate methods, that were deprecated in iOS SDK itself. Here's a list for this year:&lt;/p&gt;

&lt;p&gt;Added:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;UITableViewDelegate.tableView(_:canPerformPrimaryActionForRowAt:)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UITableViewDelegate.tableView(_:performPrimaryActionForRowAt:)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:canPerformPrimaryActionForItemAt:)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt; &lt;code&gt;UICollectionViewDelegate.collectionView(_:performPrimaryActionForItemAt:)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:contextMenuConfigurationForItemsAt:point:)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:contextMenuConfiguration:highlightPreviewForItemAt:&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:contextMenuConfiguration:dismissalPreviewForItemAt:&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Deprecated on iOS 16:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:contextMenuConfigurationForItemAt:point:)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:previewForHighlightingContextMenuWithConfiguration:)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UICollectionViewDelegate.collectionView(_:previewForDismissingContextMenuWithConfiguration:)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Thanks
&lt;/h2&gt;

&lt;p&gt;That's it folks! Thanks to all users of the frameworks, and everyone reading this document! &lt;/p&gt;

&lt;p&gt;If you are interested in full list of changes, read &lt;a href="https://github.com/DenTelezhkin/DTTableViewManager/releases"&gt;DTTableViewManager changelog&lt;/a&gt; or &lt;a href="https://github.com/DenTelezhkin/DTCollectionViewManager/releases"&gt;DTCollectionViewManager changelog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you encounter issues with frameworks, please don't hesitate to &lt;a href="https://github.com/DenTelezhkin/DTTableViewManager/issues/new"&gt;open issue&lt;/a&gt;, or &lt;a href="https://github.com/DenTelezhkin/DTTableViewManager/compare"&gt;submit a pull request&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Have a good day, everyone! &lt;/p&gt;

</description>
      <category>uitableview</category>
      <category>uicollectionview</category>
      <category>swiftui</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
