title: 'NSInternalInconsistencyException' Inserting Item with Collection View Swift 3
body: <p>So, I am using Realm as a data store, which I'm pretty sure I need to first add content to before inserting an item at index path in a collection view. But I keep getting this all too familiar error:</p>
  
  <p><code>'NSInternalInconsistencyException', reason: 'attempt to insert item 1 into section -1, but there are only 1 items in section 1 after the update'</code> </p>
  
  <p>Here is my model:</p>
  
  <pre><code>final class Listing: Object {
  dynamic var id = ""
  dynamic var name = ""
  dynamic var item = ""
  
  }
  </code></pre>
  
  <p>Here is my view controller that conforms to UICollectionView data sources and delegates:</p>
  
  <pre><code> override func viewDidLoad() {
      super.viewDidLoad()
  
      // MARK: - Get Listings!
  
      queryListings()
  
      // MARK: - Delegates
  
      self.collectionView.delegate = self
      self.collectionView.dataSource = self
  }
  
  // MARK: - Query Listings
  
  func queryListings() {
      let realm = try! Realm()
  
      let everyListing = realm.objects(Listing.self)
      let listingDates = everyArticle.sorted(byKeyPath: "created", ascending: false)
  
      for listing in listingDates {
          listing.append(listing)
          self.collectionView.performBatchUpdates({ 
              self.collectionView.insertItems(at: [IndexPath(item: self.listing.count, section: 1)])
          }, completion: nil)
      }
  }
  </code></pre>
  
  <p>Delegates:</p>
  
  <pre><code> // MARK: UICollectionViewDataSource
  
   func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
   func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return listing.count
  }
  
   func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ListingCollectionViewCell
  
      cell.awakeFromNib()
  
      return cell
  }
  </code></pre>
  
  <p>I've tried every permutation of self.listing.count 0, 1, -1 , +1 as well as section 0, 1, -1, +1 and the exception raised is the same plus or minus the section and items that exist. Calling reloadData() doesn't help either.</p>
  
  <p>Anyone solve this with a collection view?</p>