简体   繁体   中英

Not conforming to a protocol

I converted some Swift 2 code to Swift 3 and now my struct no longer conforms to a protocol. I clearly have the protocol, and every time I try reapply it, I get an another error, invalid redelacartion. I can't seem to figure out why this error is occurring. Here is my code if any one has any recommendations of whats wrong, or where to look?

struct wpOauth: wpOAuthProtocol, 🕵 {

  typealias PropertyType = ObserverProperty
  let propertyChanged = Event<ObserverProperty>()

//We'll need to access NSUserDefaults
let defaults = UserDefaults.standard


func getUserData(completionHandler: @escaping (String) -> ()) -> () {
    guard let accessToken = defaults.string(forKey: "accessToken") else {
        return
    }

    manager.request(siteUrl, method: .post, parameters: [
        "access_token": accessToken
        ]).responseJSON { response in

            guard let data = response.result.value else{
                self.propertyChanged.raise(data: .NetworkError)
                return
            }

            let json = JSON(data)

            guard (json["error"].string != nil) else{

                //Get username to be displayed in input field
                guard let displayName = json["display_name"].string else{
                    return
                }

                completionHandler(displayName)

                return
            }

    }
}

This is the Protocol

 protocol wpOAuthProtocol {
 func getUserData(completionHandler:(String) -> ()) -> ()
 }

The protocol definition doesn't match your re-declaration, which is what the error message is trying to say. Just add @escaping before (String) in your protocol definition and that should fix the error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM