[GH-ISSUE #542] Result Cannot convert value of type '(_) throws -> ()' to expected argument type #360

Closed
opened 2026-03-03 16:48:03 +03:00 by kerem · 1 comment
Owner

Originally created by @saroar on GitHub (Aug 20, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/542

###Error:

Cannot convert value of type '(_) throws -> ()' to expected argument type 'OAuthSwiftHTTPRequest.CompletionHandler?' (aka 'Optional<(Result<OAuthSwiftResponse, OAuthSwiftError>) -> ()>')

https://prnt.sc/ov83nt

Description:

old code

    func getProfilePerfect(_ oauthswift: OAuth2Swift, url: String, success: @escaping () -> Void ) {
        _ = oauthswift.client.get(
            url, success: { response in
                let data = JSON(data: response.data)
                PerfectLocalAuth.name 		= "\(data["firstname"].stringValue) \(data["lastname"].stringValue)"
                PerfectLocalAuth.firstname 	= data["firstname"].stringValue
                PerfectLocalAuth.lastname 	= data["lastname"].stringValue
                success()
        }, failure: { error in
            print(error)
        }
        )
    }

new code

    func getProfilePerfect(_ oauthswift: OAuth2Swift, url: String, success: @escaping () -> Void ) {
        _ = oauthswift.client.get( url ) { result in
            switch result {
            case .success(let response):
                let data = try JSON(data: response.data)
                PerfectLocalAuth.name         = "\(data["firstname"].stringValue) \(data["lastname"].stringValue)"
                PerfectLocalAuth.firstname     = data["firstname"].stringValue
                PerfectLocalAuth.lastname     = data["lastname"].stringValue
                success()
            case .failure(let error):
                debugPrint(#line, error)
            }
        }
    }

OAuth Provider? (Twitter, Github, ..):

facebook and vk

OAuth Version:

  • Version 1
  • [x ] Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • [x ] CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • [x ] v2.0.0
  • v1.4.1
  • v1.2.1
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • [x ] 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • 10.x (Swift 4.1)

  • 9.3 (Swift 4.1)

  • 9.0 (Swift 4.0)

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @saroar on GitHub (Aug 20, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/542 ###Error: ``` Cannot convert value of type '(_) throws -> ()' to expected argument type 'OAuthSwiftHTTPRequest.CompletionHandler?' (aka 'Optional<(Result<OAuthSwiftResponse, OAuthSwiftError>) -> ()>') ``` https://prnt.sc/ov83nt ### Description: old code ``` func getProfilePerfect(_ oauthswift: OAuth2Swift, url: String, success: @escaping () -> Void ) { _ = oauthswift.client.get( url, success: { response in let data = JSON(data: response.data) PerfectLocalAuth.name = "\(data["firstname"].stringValue) \(data["lastname"].stringValue)" PerfectLocalAuth.firstname = data["firstname"].stringValue PerfectLocalAuth.lastname = data["lastname"].stringValue success() }, failure: { error in print(error) } ) } ``` new code ``` func getProfilePerfect(_ oauthswift: OAuth2Swift, url: String, success: @escaping () -> Void ) { _ = oauthswift.client.get( url ) { result in switch result { case .success(let response): let data = try JSON(data: response.data) PerfectLocalAuth.name = "\(data["firstname"].stringValue) \(data["lastname"].stringValue)" PerfectLocalAuth.firstname = data["firstname"].stringValue PerfectLocalAuth.lastname = data["lastname"].stringValue success() case .failure(let error): debugPrint(#line, error) } } } ``` ### OAuth Provider? (Twitter, Github, ..): facebook and vk ### OAuth Version: - [ ] Version 1 - [x ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x ] CocoaPods - [ ] Swift Package Manager - [ ] Manually ### Library version: - [ ] head - [x ] v2.0.0 - [ ] v1.4.1 - [ ] v1.2.1 - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x ] 11.x (Swift 5.1) - [ ] 10.x (Swift 5.0) - [ ] 10.x (Swift 4.1) - [ ] 9.3 (Swift 4.1) - [ ] 9.0 (Swift 4.0) - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:48:03 +03:00
Author
Owner

@saroar commented on GitHub (Aug 20, 2019):

all is good sorry for post

<!-- gh-comment-id:523119683 --> @saroar commented on GitHub (Aug 20, 2019): all is good sorry for post
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#360
No description provided.