InstantSearch for Swift 4.1 - Compile problem after installing pod

Hello everyone,

I put pod 'InstantSearch', '~> 2.0‘ into my pod file and installed it.

When I now try to run my app, I get following issue:
Value of type '[String]' has no member 'compactMap'

This problem occurs in following class
@objcMembers public class FacetRefinement: NSObject {

How to solve this issue? What went wrong

Hey @kaan548,

Can you try pod 'InstantSearch', '~> 5.0' as mentioned in here and see if the project can run?

Thanks!

1 Like

Hello guy,

when I try to add 'InstantSearch', '~> 5.0' then I get the issue which I reported in the other thread

Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift

My code version supports only Swift 4.1. InstantSearch with version ~> 5.0 is for Swift 4.2 and higher.

So this is the reason why I used 'InstantSearch', '~> 2.0‘. Though in that case, I get a compile problem.

As the StackOverflow Thread mentions:

compactMap(_:) was introduced in Swift 4.1; in Swift 4.0.x it’s flatMap(_:)

What Swift version are you using in your project? if 4.0, then you might want to try to build the pod with version 4.1 by following this SO thread.

1 Like

Thanks a lot :slight_smile: I was using Swift 4.0 indeed

1 Like

Maybe one more question, since I am using Swift 4.0, the following guideline:

doesn’t work for me. E. g. I can’t use SingleIndexSearcher. What to do now :slight_smile: ?

Actually, I think you’ll be able to use the new InstantSearch v5. Do the following at the end of your podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if ['InstantSearch', 'InstantSearchClient'].include? target.name
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.0'
      end
    end
  end
end

And don’t forget to add pod 'InstantSearch', '~> 5.0' in your target.

My pod looks like following now:

target 'Delgado' do
  use_frameworks!

     pod 'Firebase/Auth‘, '~> 6.0.0’    
     pod 'Firebase/Database’, '~> 6.0.0’
     pod 'Firebase/Storage', '~> 6.0.0’
     pod 'Firebase/Core', '~> 6.0.0’
     pod 'Firebase/Firestore', '~> 6.0.0’
     pod  'Firebase/Messaging', '~> 6.0.0’
     pod 'AZDropdownMenu'
     pod 'AlgoliaSearch-Client-Swift', '~> 4.0‘
     pod 'OneSignal', '>= 2.6.2', '< 3.0'
     pod 'InstantSearch', '~> 5.0‘
  
target 'OneSignalNotificationServiceExtension' do
   pod 'OneSignal', '>= 2.6.2', '< 3.0'

end

end

        post_install do |installer|
          installer.pods_project.targets.each do |target|
            if ['InstantSearch', 'InstantSearchClient'].include? target.name
              target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '5.0'
              end
            end
          end
        end

But I am getting this issue:
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.

@kaan548 Can you let me know what Xcode version you’re using? If you don’t have the latest one, that means your Xcode doesn’t support Swift 5.

If you can’t upgrade to InstantSearch v5, you could use InstantSearch v4.0, there’s legacy documentation that you could find here: getting started programmatic - getting started storyboard - getting started part 2 - API Ref.

However I would strongly advise you to use the newest version of InstantSearch as it is much more customisable, extensible, and more components/widgets can be found. The old version of InstantSearch is being deprecated and we won’t add new features to it.

Hello @guy.daher,

thanks again for the reply. I am using Xcode 9.2. I can’t update it to a newer version since my macbook pro is too old for the current os version. So I am forced to work with Swift 4.0 at the moment. I guess, I need to work with a lower version of InstantSearch.

Installing InstantSearch with version 4 also leads to the same problem. I can’t use it.

Try to do pod 'InstantSearch', '~> 2.0', this probably works for Swift 4.0 and old Xcode versions.

Thanks :slight_smile: This works. But the documentation for the previous version seems to be uncompleted. :frowning: