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?
For anyone interested, it looks like the preferred method is to:
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With