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)
      }
    }
}
JAL
  • 41,701
  • 23
  • 172
  • 300
MattBlack
  • 3,616
  • 7
  • 32
  • 58

8 Answers8

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.

JAL
  • 41,701
  • 23
  • 172
  • 300
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'
Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
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'

n.by.n
  • 2,458
  • 22
  • 31
1

Use this instead

Change flatMap to compactMap
Community
  • 1
  • 1
  • 5
    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. – nhgrif Sep 24 '18 at 20:15
  • 1
    Worked for me . Thanks! – Vineesh TP Nov 11 '18 at 06:57
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

Abuzar Manzoor
  • 379
  • 4
  • 13
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
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.

Pramod More
  • 1,220
  • 2
  • 22
  • 51
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.

ajw
  • 2,568
  • 23
  • 27