6

I've tried to troubleshoot this warning but have had no success. Since upgrading to swift3, I am receiving a warning message in my Facebook Graph Request completion handler.

The error message is specifically, "Expression of type 'FBSDKGraphRequestConnection?'is unused."

graphRequest?.start(completionHandler: { (connection, result, error) in

            if error != nil {

                //do something with error

            } else if result != nil {

                //do something with result 
            }

        })

I've tried adding (in the completion handler) lines of code like below to see if the warning would disappear but the warning is persistent.

connection.start()

connection.timeout = 30

if connection != nil {


            }

The completion handler I have worked fine in swift2 and gave me no such warning. Am I not properly using the completion handler?

DevKyle
  • 1,091
  • 6
  • 22

2 Answers2

17

For anyone interested, it looks like the preferred method is to:

  1. Initialize FBSDKGraphRequest
  2. Initialize FBSDKGraphRequestConnection
  3. Add request to request connection
  4. Start connection.

so,

let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "email"])
        let connection = FBSDKGraphRequestConnection()
        connection.add(graphRequest, completionHandler: { (connection, result, error) in

            if error != nil {

                //do something with error

            } else {

                //do something with result

            }

        })

        connection.start()

Above seems to be preferred over graphRequest.start(), no warnings or errors.

DevKyle
  • 1,091
  • 6
  • 22
2

You can simple remove it like

In swift 3

_ = request?.start { (connection, result, error) in    
    }

In swift 2.x

let _ = request?.start { (connection, result, error) in    
        }
UnRewa
  • 2,462
  • 2
  • 29
  • 31