Xcode 10 FBSDK 'SDKLoggingBehavior
Asked Answered
C

8

15

I have updated to Xcode 10 and and am unable to compile my code. I get the following error from the Facebook SDK (FacebookCore).

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

On line

return Set(behaviors)

I have installed the lastest FBSDK using cocoapods.

How would I go about resolving this or is it a case of waiting for an updated SDK from FB?

extension SDKSettings {
      /**
       Current logging behaviors of Facebook SDK.
       The default enabled behavior is `.DeveloperErrors` only.
       */
      public static var enabledLoggingBehaviors: Set<SDKLoggingBehavior> {
        get {
          let behaviors = FBSDKSettings.loggingBehavior().flatMap { 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))
        }
      }

      /**
       Enable a particular Facebook SDK logging behavior.

       - parameter behavior: The behavior to enable
       */
      public static func enableLoggingBehavior(_ behavior: SDKLoggingBehavior) {
        FBSDKSettings.enableLoggingBehavior(behavior.sdkStringValue)
      }

      /**
       Disable a particular Facebook SDK logging behavior.

       - parameter behavior: The behavior to disable.
       */
      public static func disableLoggingBehavior(_ behavior: SDKLoggingBehavior) {
        FBSDKSettings.disableLoggingBehavior(behavior.sdkStringValue)
      }
    }
}
Chongchoo answered 6/6, 2018 at 16:8 Comment(0)
L
14

This is fixed in the latest release, 0.3.1 (as of June 8th, 2018).

Old answer:

This is fixed in the latest master, but not in the latest tag or Cocoapod release.

To use this, clone the code directly from the master branch into your project from the Swift SDK repo, or change your podfile to point to master:

pod 'FacebookCore', :git => 'https://github.com/facebook/facebook-sdk-swift', :branch => 'master'

The pull request that fixed this issue can be found here.

Leaf answered 6/6, 2018 at 21:31 Comment(1)
installing pods still getting version 0.3.0Klipspringer
K
9

Adding to @JAL's answer:

For me, installing pods still giving me version 0.3.0

modifying PodFile with latest version number gives me latest sdk

  pod 'FacebookCore','0.5.0'
  pod 'FacebookLogin','0.5.0'
  pod 'FacebookShare','0.5.0'
Klipspringer answered 21/10, 2018 at 9:4 Comment(1)
My mid 2011 mac is limited to xCode 10.1 working fine by this pod.Zerk
Y
3
  1. Set Deployement Target to 11.0 (In Project & Podfile)
  2. Do 'pod repo update'
  3. Update your Podfile as follows:

    pod 'FacebookCore', :git => 'https://github.com/facebook/facebook-sdk-swift', :branch => 'master'

    pod 'FacebookLogin', :git => 'https://github.com/facebook/facebook-sdk-swift', :branch => 'master'

    pod 'FacebookShare', :git => 'https://github.com/facebook/facebook-sdk-swift', :branch => 'master'

Yance answered 24/9, 2018 at 9:6 Comment(0)
I
1

Use this instead

Change flatMap to compactMap
Insinuating answered 24/9, 2018 at 15:53 Comment(2)
Unfortunately, this isn't a great answer for most users. It's very common practice for dependencies installed via CocoaPods to not be checked into git, so while this may fix the problem locally, it doesn't fix the problem for other people working on the same code base.Forage
Worked for me . Thanks!Mulkey
R
1

In xcode 10. This works for me.

1. change the iOS version 11.0
2. for swift 4.2 replace flatMap() to compactMap()
3. delete the derived data of project.
4. clean and run the project on simulator


Change flatMap to compactMap

hope it helps

Ra answered 11/10, 2018 at 6:20 Comment(0)
C
0

Just update your pod and its working fine for me

  1. Open terminal and set the project path
  2. 'pod repo update'
  3. Deployment Target 11.0 or above
Clomb answered 25/9, 2018 at 9:7 Comment(0)
I
0

enter image description here I was getting error at following code

 get {
      let createBehavior = { (object: AnyHashable) -> SDKLoggingBehavior? in
        if let value = object as? String {
          return SDKLoggingBehavior(sdkStringValue: value)
        }
        return nil
      }

     #if swift(>=4.1)
         //line of error
            let behaviors: [SDKLoggingBehavior] = FBSDKSettings.loggingBehaviors.compactMap(createBehavior)
          #endif
          #else
          let behaviors: [SDKLoggingBehavior] = FBSDKSettings.loggingBehaviors.flatMap(createBehavior)
          #endif

I changed code to

 let behaviors: [SDKLoggingBehavior] = (FBSDKSettings.loggingBehaviors?.compactMap({ (object) -> SDKLoggingBehavior? in
            if let value = object as? String {
                return SDKLoggingBehavior(sdkStringValue: value)
            }
            return nil
        })) ?? []

Fixed issue for me.

Incorporator answered 24/4, 2019 at 13:42 Comment(0)
J
0

If you are working with Xcode 10 with Swift 4.2 make sure to use both

pod 'FacebookLogin', '0.5.0'
pod 'FacebookCore', '0.5.0'

if you only use

pod 'FacebookLogin', '0.5.0'

It will automatically install FacebookCore -> 0.6.0 which is not supported.

Jo answered 7/7, 2019 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.