2

I am using https://github.com/kylef/JSONWebToken.swift package for handling encoding and decoding of JWT.

I am on Swfit 3 and xcode 8.0.1. The problem that I am having is, after importing JWT into my controller file, when I call

JWT.encode(claims: ["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!))

The compiler complains:

Ambiguous reference to member 'encode(_:algorithm)'.

I then pressed command + click on the JWT.encode method and traced the method down and found out that the JWT.encode method actually referencing to the .encode method in MultipartFormData.swift of Alamofire.

I have imported both JWT and Alamofire.

Basically, the JWT and Alamofire MultipartFormData.swift both have a public method called encode, and I am calling it explicitly JWT.encode, why would it refer to the encode method in the Foundation library?

How should I fix it?

Thanks

Captain Rib
  • 285
  • 1
  • 6
  • 17

1 Answers1

3

Did you try to prefix the method name with the module? It should work according to this answer: https://stackoverflow.com/a/25232124/250164


EDIT: I think I figured it out. Your function signature is wrong, hence the encode method cannot be found. Use the following code instead, this seems to work for me:

JWT.encode(["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!))
Community
  • 1
  • 1
Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92