IGListKit/docs/best-practices-and-faq.html
Ryan Nystrom bccef16555 Regenerate docs for 3.4
Summary:
See title
Closes https://github.com/Instagram/IGListKit/pull/1164

Differential Revision: D7838218

Pulled By: rnystrom

fbshipit-source-id: f9e1aa63b5d3a846fc155bd010f6d17e27a1b1ab
2018-05-01 17:04:28 -07:00

399 lines
28 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Best Practices and FAQ Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
</head>
<body>
<a title="Best Practices and FAQ Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">IGListKit Docs</a> (98% documented)</p>
<p class="header-right"><a href="https://github.com/Instagram/IGListKit"><img src="img/gh.png"/>View on GitHub</a></p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">IGListKit Reference</a>
<img id="carat" src="img/carat.png" />
Best Practices and FAQ Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="best-practices-and-faq.html">Best Practices and FAQ</a>
</li>
<li class="nav-group-task">
<a href="generating-your-models.html">Generating your models</a>
</li>
<li class="nav-group-task">
<a href="getting-started.html">Getting Started</a>
</li>
<li class="nav-group-task">
<a href="iglistdiffable-and-equality.html">IGListDiffable and Equality</a>
</li>
<li class="nav-group-task">
<a href="installation.html">Installation</a>
</li>
<li class="nav-group-task">
<a href="migration.html">Migration</a>
</li>
<li class="nav-group-task">
<a href="modeling-and-binding.html">Modeling and Binding</a>
</li>
<li class="nav-group-task">
<a href="vision.html">VISION</a>
</li>
<li class="nav-group-task">
<a href="working-with-core-data.html">Working with Core Data</a>
</li>
<li class="nav-group-task">
<a href="working-with-uicollectionview.html">Working with UICollectionView</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/IGListAdapter.html">IGListAdapter</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListAdapterUpdater.html">IGListAdapterUpdater</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListBatchUpdateData.html">IGListBatchUpdateData</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListBindingSectionController.html">IGListBindingSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListCollectionView.html">IGListCollectionView</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListCollectionViewLayout.html">IGListCollectionViewLayout</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListGenericSectionController.html">IGListGenericSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListIndexPathResult.html">IGListIndexPathResult</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListIndexSetResult.html">IGListIndexSetResult</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListMoveIndex.html">IGListMoveIndex</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListMoveIndexPath.html">IGListMoveIndexPath</a>
</li>
<li class="nav-group-task">
<a href="Classes.html#/c:objc(cs)IGListReloadDataUpdater">IGListReloadDataUpdater</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListSectionController.html">IGListSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListSingleSectionController.html">IGListSingleSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListStackedSectionController.html">IGListStackedSectionController</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Constants.html">Constants</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Constants.html#/c:@IGListKitVersionNumber">IGListKitVersionNumber</a>
</li>
<li class="nav-group-task">
<a href="Constants.html#/c:@IGListKitVersionString">IGListKitVersionString</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Enums/IGListAdapterUpdateType.html">IGListAdapterUpdateType</a>
</li>
<li class="nav-group-task">
<a href="Enums/IGListDiffOption.html">IGListDiffOption</a>
</li>
<li class="nav-group-task">
<a href="Enums/IGListExperiment.html">IGListExperiment</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Protocols/IGListAdapterDataSource.html">IGListAdapterDataSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterDelegate.html">IGListAdapterDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterMoveDelegate.html">IGListAdapterMoveDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterUpdateListener.html">IGListAdapterUpdateListener</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterUpdaterDelegate.html">IGListAdapterUpdaterDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBatchContext.html">IGListBatchContext</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindable.html">IGListBindable</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindingSectionControllerDataSource.html">IGListBindingSectionControllerDataSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindingSectionControllerSelectionDelegate.html">IGListBindingSectionControllerSelectionDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListCollectionContext.html">IGListCollectionContext</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListCollectionViewDelegateLayout.html">IGListCollectionViewDelegateLayout</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListDiffable.html">IGListDiffable</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListDisplayDelegate.html">IGListDisplayDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListScrollDelegate.html">IGListScrollDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListSingleSectionControllerDelegate.html">IGListSingleSectionControllerDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListSupplementaryViewSource.html">IGListSupplementaryViewSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListTransitionDelegate.html">IGListTransitionDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListUpdatingDelegate.html">IGListUpdatingDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListWorkingRangeDelegate.html">IGListWorkingRangeDelegate</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Type Definitions.html">Type Definitions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListItemUpdateBlock">IGListItemUpdateBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListObjectTransitionBlock">IGListObjectTransitionBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListReloadUpdateBlock">IGListReloadUpdateBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellConfigureBlock">IGListSingleSectionCellConfigureBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellSizeBlock">IGListSingleSectionCellSizeBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListToObjectBlock">IGListToObjectBlock</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListAdapter.h@T@IGListUpdaterCompletion">IGListUpdaterCompletion</a>
</li>
<li class="nav-group-task">
<a href="Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListUpdatingCompletion">IGListUpdatingCompletion</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Functions.html">Functions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiff">IGListDiff</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiffExperiment">IGListDiffExperiment</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiffPaths">IGListDiffPaths</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiffPathsExperiment">IGListDiffPathsExperiment</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:IGListExperiments.h@F@IGListExperimentEnabled">IGListExperimentEnabled</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1 id='best-practices-and-faqs' class='heading'>Best Practices and FAQs</h1>
<p>This guide provides notes and details on best practices in using <code>IGListKit</code>, general tips, and answers to FAQs.</p>
<h2 id='best-practices' class='heading'>Best Practices</h2>
<ul>
<li>We recommend adding an assert to check <a href="https://developer.apple.com/reference/objectivec/1418956-nsobject/1418511-iskindofclass"><code>-isKindOfClass:</code></a> on the object you receive in <a href="https://github.com/Instagram/IGListKit/blob/master/Source/IGListSectionController.h#L63-L72"><code>-didUpdateToObject:</code></a> in your section controllers.
This makes it easy to track down easily-overlooked mistakes in your <a href="https://instagram.github.io/IGListKit/Protocols/IGListAdapterDataSource.html#/c:objc(pl)IGListAdapterDataSource(im)listAdapter:sectionControllerForObject:"><code>IGListAdapaterDataSource</code></a> implementation.
If this assert is ever hit, that means <code>IGListKit</code> has sent your section controller the incorrect type of object.
This would only happen if your objects provide <em>non-unique</em> diff identifiers.</li>
</ul>
<pre class="highlight plaintext"><code>// Objective-C
- (void)didUpdateToObject:(id)object {
NSParameterAssert([object isKindOfClass:[MyModelClass class]]);
_myModel = object;
}
</code></pre>
<pre class="highlight swift"><code><span class="c1">// Swift</span>
<span class="kd">func</span> <span class="nf">didUpdate</span><span class="p">(</span><span class="n">to</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">Any</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">precondition</span><span class="p">(</span><span class="n">object</span> <span class="k">is</span> <span class="kt">MyModelClass</span><span class="p">)</span>
<span class="n">myModel</span> <span class="o">=</span> <span class="n">object</span> <span class="k">as!</span> <span class="kt">MyModelClass</span>
<span class="p">}</span>
</code></pre>
<ul>
<li><p>Make sure your <a href="https://instagram.github.io/IGListKit/Protocols/IGListDiffable.html#/c:objc(pl)IGListDiffable(im)diffIdentifier"><code>-diffIdentifier</code></a> implementation returns a <strong>unique identifier</strong> for each object.</p></li>
<li><p>We highly recommend using single-item sections when possible. That is, each section controller manages a single model (which may have one or multiple cells). This gives you the greatest amount of flexibility, modularity, and re-use for your components.</p></li>
</ul>
<h2 id='frequently-asked-questions' class='heading'>Frequently asked questions</h2>
<h4 id='i-upgraded-iglistkit-and-now-everything-is-broken' class='heading'>I upgraded IGListKit and now everything is broken!</h4>
<p>Check out our <a href="https://github.com/Instagram/IGListKit/blob/master/Guides/Migration.md">migration guide</a> to make upgrading easier.</p>
<h4 id='how-do-you-implement-separators-between-cells' class='heading'>How do you implement separators between cells?</h4>
<p>See discussion in <a href="https://github.com/Instagram/IGListKit/issues/329">#329</a></p>
<h4 id='how-do-i-fix-the-error-code-could-not-build-objective-c-module-39-iglistkit-39-code' class='heading'>How do I fix the error <code>Could not build Objective-C module &#39;IGListKit&#39;</code>?</h4>
<p>See discussion in <a href="https://github.com/Instagram/IGListKit/issues/316">#316</a></p>
<h4 id='the-documentation-and-examples-have-code-lt-x-gt-code-feature-or-changes-but-i-don-39-t-have-it-in-my-version-why' class='heading'>The documentation and examples have <code>&lt;X&gt;</code> feature or changes, but I don&rsquo;t have it in my version. Why?</h4>
<p>This feature is on the <code>master</code> branch only and hasn&rsquo;t been officially tagged and <a href="https://github.com/Instagram/IGListKit/releases">released</a>. If you need to, you can <a href="https://instagram.github.io/IGListKit/installation.html">install from the <code>master</code> branch</a>.</p>
<h4 id='does-code-iglistkit-code-work-with' class='heading'>Does <code>IGListKit</code> work with&hellip;?</h4>
<ul>
<li>Core Data (<a href="https://instagram.github.io/IGListKit/working-with-core-data.html">Working with Core Data</a> Guide)</li>
<li>AsyncDisplayKit (<a href="https://github.com/facebook/AsyncDisplayKit/pull/2942">AsyncDisplayKit/#2942</a>)</li>
<li>ComponentKit (<a href="https://github.com/ocrickard/IGListKit-ComponentKit">ocrickard/IGListKit-ComponentKit</a>)</li>
<li>RxSwift (<a href="https://github.com/yuzushioh/RxIGListKit">yuzushioh/RxIGListKit</a>)</li>
<li>React Native</li>
<li>Reactive Cocoa</li>
</ul>
<p>Yes.</p>
<h4 id='does-code-iglistkit-code-work-with-code-uitableview-code' class='heading'>Does <code>IGListKit</code> work with <code>UITableView</code>?</h4>
<p>No, but you can install the <a href="https://instagram.github.io/IGListKit/installation.html">diffing subspec via CocoaPods</a>.</p>
<h4 id='what-39-s-the-purpose-of-code-iglistcollectionview-code' class='heading'>What&rsquo;s the purpose of <code><a href="Classes/IGListCollectionView.html">IGListCollectionView</a></code>?</h4>
<p>Historically, we used this subclass to gain compile-time safety to prevent disallowed methods from being called on <code>UICollectionView</code>, because <code>IGListKit</code> handles model and view updates. However, it has since been removed. See discussion at <a href="https://github.com/Instagram/IGListKit/issues/409">#409</a>.</p>
<h4 id='how-can-i-manage-cell-selection-and-deselection' class='heading'>How can I manage cell selection and deselection?</h4>
<p>See discussion at <a href="https://github.com/Instagram/IGListKit/issues/184">#184</a>.</p>
<h4 id='i-have-a-em-huge-em-data-set-and-a-href-https-instagram-github-io-iglistkit-classes-iglistadapter-html-c-objc-cs-iglistadapter-im-performupdatesanimated-completion-code-performupdatesanimated-completion-code-a-is-em-super-em-slow-what-do-i-do' class='heading'>I have a <em>huge</em> data set and <a href="https://instagram.github.io/IGListKit/Classes/IGListAdapter.html#/c:objc(cs)IGListAdapter(im)performUpdatesAnimated:completion:"><code>-performUpdatesAnimated: completion:</code></a> is <em>super</em> slow. What do I do?</h4>
<p>If you have multiple thousands of items and you cannot batch them in, you&rsquo;ll see performance issues with <code>-performUpdatesAnimated: completion:</code>. The real bottle neck behind the scenes here is <code>UICollectionView</code> attempting to insert so many cells at once. Instead, call <a href="https://instagram.github.io/IGListKit/Classes/IGListAdapter.html#/c:objc(cs)IGListAdapter(im)reloadDataWithCompletion:"><code>-reloadDataWithCompletion:</code></a> when you first load data. Behind the scenes, this method <em>does not</em> do any diffing and simply calls <code>-reloadData</code> on <code>UICollectionView</code>. For subsequent updates, you can then use <code>-performUpdatesAnimated: completion:</code>.</p>
<h4 id='how-do-i-use-iglistkit-and-estimated-cell-sizes-with-auto-layout' class='heading'>How do I use IGListKit and estimated cell sizes with Auto Layout?</h4>
<p>This should work in theory, and we have an <a href="https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/SectionControllers/SelfSizingSectionController.swift">example section controller</a>, but the estimated-size API in <code>UICollectionViewFlowLayout</code> has changed dramatically over different iOS versions, making first-class support in IGListKit difficult. We don&rsquo;t use estimated cell sizes or Auto Layout in Instagram and cannot commit to fully supporting it.</p>
<p>See <a href="https://github.com/Instagram/IGListKit/issues/516">#516</a> for a master list of all known issues. We very much welcome contribution to fixing this!</p>
<h4 id='is-creating-a-q-wrapper-q-model-just-for-iglistkit-ok' class='heading'>Is creating a <q>wrapper</q> model just for IGListKit ok?</h4>
<p>Yes! We create models that act as a grab-bag for other models, specifically for use in section controllers. Things like:</p>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">WeatherSectionModel</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">location</span><span class="p">:</span> <span class="kt">Location</span>
<span class="k">let</span> <span class="nv">forecast</span><span class="p">:</span> <span class="kt">Forecast</span>
<span class="k">let</span> <span class="nv">conditions</span><span class="p">:</span> <span class="kt">Conditions</span>
<span class="p">}</span>
</code></pre>
<p>Just don&rsquo;t forget to make your models diffable using the data in the contained models:</p>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">WeatherSectionModel</span><span class="p">:</span> <span class="kt">ListDiffable</span> <span class="p">{</span>
<span class="kd">func</span> <span class="nf">diffIdentifier</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">NSObjectProtocol</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">location</span><span class="o">.</span><span class="n">identifier</span>
<span class="p">}</span>
<span class="kd">func</span> <span class="nf">isEqual</span><span class="p">(</span><span class="n">toDiffableObject</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">ListDiffable</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="k">guard</span> <span class="k">self</span> <span class="o">!==</span> <span class="n">object</span> <span class="k">else</span> <span class="p">{</span> <span class="k">return</span> <span class="kc">true</span> <span class="p">}</span>
<span class="k">guard</span> <span class="k">let</span> <span class="nv">object</span> <span class="o">=</span> <span class="n">object</span> <span class="k">as?</span> <span class="kt">WeatherSectionModel</span> <span class="k">else</span> <span class="p">{</span> <span class="k">return</span> <span class="kc">false</span> <span class="p">}</span>
<span class="k">return</span> <span class="n">location</span> <span class="o">==</span> <span class="n">object</span><span class="o">.</span><span class="n">location</span> <span class="o">&amp;&amp;</span> <span class="n">forecast</span> <span class="o">==</span> <span class="n">object</span><span class="o">.</span><span class="n">forecast</span> <span class="o">&amp;&amp;</span> <span class="n">conditions</span> <span class="o">==</span> <span class="n">object</span><span class="o">.</span><span class="n">conditions</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h4 id='what-if-i-want-to-make-my-swift-structs-diffable' class='heading'>What if I want to make my Swift structs diffable?</h4>
<p>Give <a href="https://github.com/Instagram/IGListKit/issues/35#issuecomment-277503724">this box</a> a try.</p>
<h4 id='i-want-to-deliver-messages-to-certain-section-controllers-how-do-i-do-that' class='heading'>I want to deliver messages to certain section controllers, how do I do that?</h4>
<p>We recommend using dependency injection and announcing changes, demonstrated in <a href="https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/ViewControllers/AnnouncingDepsViewController.swift">our example</a>.</p>
<h4 id='should-i-reuse-my-section-controllers-between-models' class='heading'>Should I reuse my section controllers between models?</h4>
<p>No! <code>IGListKit</code> is designed to have a 1:1 instance mapping between objects and section controllers. <code>IGListKit</code> does not reuse section controllers, and if you do unintended behaviors will occur.</p>
<p><code>IGListKit</code> <em>does</em> still use <code>UICollectionView</code>&lsquo;s cell reuse, so you shouldn&rsquo;t be concerned about performance.</p>
<h4 id='why-does-code-uicollectionviewflowlayout-code-put-everything-in-a-new-row' class='heading'>Why does <code>UICollectionViewFlowLayout</code> put everything in a new row?</h4>
<p><code>UICollectionViewFlowLayout</code> has its limitations, and it&rsquo;s not well designed to support sections on the same <q>line</q>. Instead you should use <a href="https://github.com/Instagram/IGListKit/blob/master/Source/IGListCollectionViewLayout.h"><code><a href="Classes/IGListCollectionViewLayout.html">IGListCollectionViewLayout</a></code></a>.</p>
<h4 id='what-if-i-just-want-a-section-controller-and-don-39-t-need-the-object' class='heading'>What if I just want a section controller and don&rsquo;t need the object?</h4>
<p>Feel free to use a static string or number as your model. You can use this object as a <q>key</q> to find your section controller. Take a look at our <a href="https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/ViewControllers/SearchViewController.swift#L34">example</a> of this.</p>
<h4 id='how-do-i-make-my-cells-diff-and-animate' class='heading'>How do I make my cells diff and animate?</h4>
<p>Use <a href="https://github.com/Instagram/IGListKit/blob/master/Source/IGListBindingSectionController.h"><code><a href="Classes/IGListBindingSectionController.html">IGListBindingSectionController</a></code></a> to automatically diff and animate your cells.</p>
<h4 id='how-can-i-power-and-update-the-number-of-items-in-a-section-controller-with-a-dynamic-array' class='heading'>How can I power and update the number of items in a section controller with a dynamic array?</h4>
<p>We recommend creating a model that owns an array to the items that power <code>numberOfItems</code>. Checkout our <a href="https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/SectionControllers/PostSectionController.m#L32">Post example</a> that has dynamic comment cells. Just be sure to check when your array changes:</p>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">Forecast</span><span class="p">:</span> <span class="kt">ListDiffable</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">day</span><span class="p">:</span> <span class="kt">Date</span>
<span class="k">let</span> <span class="nv">hourly</span><span class="p">:</span> <span class="p">[</span><span class="kt">HourlyForecast</span><span class="p">]</span>
<span class="kd">func</span> <span class="nf">diffIdentifier</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">NSObjectProtocol</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">day</span>
<span class="p">}</span>
<span class="kd">func</span> <span class="nf">isEqual</span><span class="p">(</span><span class="n">toDiffableObject</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">ListDiffable</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="k">guard</span> <span class="k">self</span> <span class="o">!==</span> <span class="n">object</span> <span class="k">else</span> <span class="p">{</span> <span class="k">return</span> <span class="kc">true</span> <span class="p">}</span>
<span class="k">guard</span> <span class="k">let</span> <span class="nv">object</span> <span class="o">=</span> <span class="n">object</span> <span class="k">as?</span> <span class="kt">Forecast</span> <span class="k">else</span> <span class="p">{</span> <span class="k">return</span> <span class="kc">false</span> <span class="p">}</span>
<span class="k">return</span> <span class="n">hourly</span> <span class="o">==</span> <span class="n">object</span><span class="o">.</span><span class="n">hourly</span> <span class="c1">// compare elements in the arrays</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="https://twitter.com/fbOpenSource" target="_blank" rel="external">Instagram</a>. All rights reserved. (Last updated: 2018-05-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.1</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>