algolia / instantsearch-ios

⚡️ A library of widgets and helpers to build instant-search applications on iOS.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/ios/
Apache License 2.0
591 stars 55 forks source link

Xcode 16 beta build error #318

Open arpa-srf opened 3 weeks ago

arpa-srf commented 3 weeks ago

Describe the bug 🐛 Build with instantsearch-ios as a dependency fails on Xcode 16 beta

Errors:

Type 'PageMap<Item>' does not conform to protocol 'Sequence'
Type 'PageMap<Item>' does not conform to protocol 'BidirectionalCollection'
Type 'PageMap<Item>' does not conform to protocol 'Collection'

To Reproduce 🔍 Steps to reproduce the behavior:

  1. Create new Project
  2. Add instantsearch-ios as a package dependency
  3. Build project

(Also possible to reproduce with Examples project in repo)

Expected behavior 💭 Build succeeds

Screenshots 🖥 Errors in PageMap.swift

PageMap Errors

Environment:

r3econ commented 3 weeks ago

I'm facing the same problem, is there any fix planned?

mohpor commented 3 weeks ago

Same

NolanOfficial commented 3 weeks ago

Same issue here. For anyone who needs it right now, it looks like PageMap now needs to conform to IteratorProtocol and Collection.

By no means is this a fix, but if you need it to build for whatever purposes for updating to Xcode 16, here's what I have so far:

Add this to the PageMap file

extension PageMap: IteratorProtocol {
    typealias Element = Item

    mutating func next() -> Item? {
        guard let index = latestPageIndex else { return nil }
        return page(atIndex: index)?.items.first
    }
}

extension PageMap: Collection {
    subscript(position: Int) -> Item {
        get {
            return page(atIndex: position)!.items.first!
        }
    }
}

Remove this from the PageMap file (or leave it, just gives a warning)

extension PageMap: Sequence {
  public func makeIterator() -> IndexingIterator<PageMap> {
    return IndexingIterator(_elements: self)
  }
squarefrog commented 2 weeks ago

We just removed the conformance to Sequence (remove these lines) and it builds without issue. Given this is an internal type and no errors are thrown its likely this isnt used anymore.

This allowed us to build our project with Xcode 16

  1. Clone instantsearch-ios
  2. Remove the conformance to Sequence from PageMap.swift
  3. In Xcode go to add a local package, and pick your cloned instantsearch dir
  4. Say yes you want to replace existing package
  5. Add the targets you need
  6. Build

It should go without saying that this is recommended only for trying Xcode 16 and not for shipping.