Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FBSDKRequestConnection warning swift3

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?

like image 541
DevKyle Avatar asked Sep 26 '16 21:09

DevKyle


2 Answers

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.

like image 131
DevKyle Avatar answered Nov 14 '22 20:11

DevKyle


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    
        }
like image 2
UnRewa Avatar answered Nov 14 '22 19:11

UnRewa