Search code examples
iosswiftxcodefacebookfacebook-sdk-4.0

Facebook SDK with Swift 4/Xcode 10: Argument type 'SDKLoggingBehavior?' does not conform to expected type 'Sequence'


I'm revisiting an old project (built with Swift 3 and now using Swift 4) and it looks like there are some issues with the Facebook SDK.

I googled the initial issues and came upon a solution here which advises adding to my pod file:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if ['FacebookCore', 'FacebookLogin'].include? target.name
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '3.2'
            end
        end
    end
end

Here is the complete podfile.

After pod install and running the project, it seemed to clear up my previous error, however I still get one error in Pods>Pods>FacebookCore>SDKSettings.swift>enabledLoggingBehaviors on line 151 return Set(behaviors)

The error is (pic):

Argument type 'SDKLoggingBehavior?' does not conform to expected type 'Sequence'

I'm not sure how to handle this error, does anyone know how to fix this to get the Facebook SDK working again?

Thanks in advance for any help!


Solution

  • inside SDKSetting.swift

    replace your enabledLoggingBehaviors function with

    public static var enabledLoggingBehaviors: Set<SDKLoggingBehavior> {
        get {
          let behaviors = FBSDKSettings.loggingBehavior().compactMap { object -> SDKLoggingBehavior? in
            if let value = object as? String {
              return SDKLoggingBehavior(sdkStringValue: value)
            }
            return nil
          }
          return Set(behaviors)
        }
        set {
          let behaviors = newValue.map({ $0.sdkStringValue })
          FBSDKSettings.setLoggingBehavior(Set(behaviors))
        }
      }
    

    Hope It Helps.