請不要因爲「模糊使用...」的重複而關閉。即使經過深入研究,我也無法找到任何類似的線索來解決我的問題。Swift 3 /如何解決:「模糊使用'授權(_:完成:)'」
我更新了一個項目,斯威夫特3和我停留在一個編譯器錯誤:
Ambiguous use of 'authorize(_:completion:)'
代碼:
func connectToInstagram() {
let auth: NSMutableDictionary = ["client_id": INSTAGRAM_CLIENT_ID,
SimpleAuthRedirectURIKey: INSTAGRAM_REDIRECT_URI]
SimpleAuth.configuration()["instagram"] = auth
SimpleAuth.authorize("instagram") { (anyObject, error) in // error here
if anyObject != nil {...
SimpleAuth是一個框架來處理社會化媒體認證用Objective C.
SimpleAuth:
open class SimpleAuth : NSObject {
open class func authorize(_ provider: String!, completion: SimpleAuth.SimpleAuthRequestHandler!)
SimpleAuthRequestHandler:
public typealias SimpleAuthRequestHandler = (Any?, Error?) -> Swift.Void
public let SimpleAuthPresentInterfaceBlockKey: String
public let SimpleAuthDismissInterfaceBlockKey: String
我試圖行更改爲:
_ = SimpleAuth.authorize("instagram") { (anyObject: Any?, error: Error?) in
_ = SimpleAuth.authorize("instagram", completion: { (anyObject: Any?, error: Error?) in
但是,正如預期的,它並沒有改變任何東西。我錯過了什麼?非常感謝幫助。
生成日誌:
xy/InstagramVC.swift:409:9: error: ambiguous use of 'authorize(_:completion:)'
SimpleAuth.authorize("instagram") { (any: Any?, error: Error?) -> Swift.Void in
^
SimpleAuth.SimpleAuth:24:21: note: found this candidate
open class func authorize(_ provider: String!, completion: SimpleAuth.SimpleAuthRequestHandler!)
^
SimpleAuth.SimpleAuth:34:21: note: found this candidate
open class func authorize(_ provider: String!, options: [AnyHashable : Any]! = [:], completion: SimpleAuth.SimpleAuthRequestHandler!)
嘗試檢查構建日誌,或者只是從命令行構建。據我記得編譯器可以給你的罪犯列表產生歧義。 – courteouselk
@AntonBronnikov我編輯了構建日誌信息的問題 –
如果我錯了,請糾正我,但是這兩種方法(帶有'options'參數的那個方法有默認值,所以可以減少與另一個簽名完全一樣)。嘗試刪除默認值(該位:'= [:]'), – courteouselk