2016-10-21 30 views
0

請不要因爲「模糊使用...」的重複而關閉。即使經過深入研究,我也無法找到任何類似的線索來解決我的問題。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!) 

enter image description here

SimpleAuthRequestHandler:

public typealias SimpleAuthRequestHandler = (Any?, Error?) -> Swift.Void 

public let SimpleAuthPresentInterfaceBlockKey: String 
public let SimpleAuthDismissInterfaceBlockKey: String 

enter image description here

我試圖行更改爲:

_ = SimpleAuth.authorize("instagram") { (anyObject: Any?, error: Error?) in 

_ = SimpleAuth.authorize("instagram", completion: { (anyObject: Any?, error: Error?) in 

但是,正如預期的,它並沒有改變任何東西。我錯過了什麼?非常感謝幫助。

生成日誌:

enter image description here

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!) 
+0

嘗試檢查構建日誌,或者只是從命令行構建。據我記得編譯器可以給你的罪犯列表產生歧義。 – courteouselk

+0

@AntonBronnikov我編輯了構建日誌信息的問題 –

+0

如果我錯了,請糾正我,但是這兩種方法(帶有'options'參數的那個方法有默認值,所以可以減少與另一個簽名完全一樣)。嘗試刪除默認值(該位:'= [:]'), – courteouselk

回答

1

的問題是與API。他們提供了這兩個功能:

open class func authorize(_ provider: String!, completion: SimpleAuth.SimpleAuthRequestHandler!)

open class func authorize(_ provider: String!, options: [AnyHashable : Any]! = [:], completion: SimpleAuth.SimpleAuthRequestHandler!)

但你可以看到第二個函數的參數options已經給出了默認參數([:])。所以當你不要指定options參數時,編譯器不能告訴你想要調用哪個函數。

這意味着第一個功能不能使用。您將始終必須使用第二個函數並傳遞一個明確的options參數。所以:

authorize("instagram", options: [:]) { (any: Any?, error: Error?) -> Void in ... }

這可能是值得記錄缺陷與SimpleAuth框架作者(S)。