Moya: Alamofire ParameterEncoding

Created on 26 Sep 2016  路  10Comments  路  Source: Moya/Moya

It looks like Alamofire removed ParameterEncoding enum for a Protocol of the same name.

We typealias locally here and use it in Endpoint.

The docs should be updated to remove the enum values.

Will the change cause issues with Moya's usage of ParameterEncoding?

bug? question

Most helpful comment

@marcelofabri I forgot to report back on this. Following your suggestion of explicitly adding Alamofire to the podspec dependencies seems to have fixed this issue for me.

All 10 comments

Great question, thanks for linking to relevant code :bow: We definitely need to do something here, at least in docs. I'll take a look later today and see what we can do.

Any word on a fix for this? It is unclear to me at this point how to properly encode requests.

Edit: It seems that using URLEncoding() and JSONEncoding() instead of Moya.ParameterEncoding.URL and Moya.ParameterEncoding.JSON does the trick, for now at least.

As in:

public var encoding: Moya.ParameterEncoding {
    if self.method == .GET || self.method == .HEAD {
        return URLEncoding()
    }
    else {
        return JSONEncoding()
    }
}

Cool, that sounds like a good fix @RamwiseMatt. I think we just need to update our docs then, right? Anyone available for a pull request?

Just a heads up, I'm using 8.0 Beta 2 in a framework project I'm working on and this is giving me fits. Using @RamwiseMatt solution in my endpoint closure:

let endpointClosure = { (target: RebatesProvider) -> Endpoint<RebatesProvider> in
  let url = target.baseURL.appendingPathComponent(target.path).absoluteString
  var encoding: Moya.ParameterEncoding = JSONEncoding()

  switch target.method {
    case .GET:
      encoding = URLEncoding()
    default:
      encoding = JSONEncoding()
  }

  let endpoint: Endpoint<RebatesProvider> = Endpoint<RebatesProvider>(URL: url, sampleResponseClosure: {.networkResponse(200, target.sampleData)}, method: target.method, parameters: target.parameters, parameterEncoding: encoding)

  return endpoint
}

gives me the following compiler errors:

Undefined symbols for architecture x86_64:
  "type metadata for Alamofire.URLEncoding", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
  "type metadata for Alamofire.JSONEncoding", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
  "protocol witness table for Alamofire.URLEncoding : Alamofire.ParameterEncoding in Alamofire", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
  "protocol witness table for Alamofire.JSONEncoding : Alamofire.ParameterEncoding in Alamofire", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
  "static Alamofire.URLEncoding.default.getter : Alamofire.URLEncoding", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
  "static Alamofire.JSONEncoding.default.getter : Alamofire.JSONEncoding", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of OffersKit.Rebates.(init () -> OffersKit.Rebates).(closure #1) in Rebates.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Commenting out my endpoint closure and removing it from the provider initializer causes everything to work just fine.

Hey @bryanbartow, only typo I found in your code is the .GET instead of .get enum case, otherwise it should be good to go. I've tested it in the Moya demo and was building correctly. If there are still some errors and cleaning doesn't help, let us know!

Also I've made a PR with the ParameterEncoding changes so I'm gonna close this one in favor of #709. If you guys could chime in there, it would be awesome! 馃憡

@bryanbartow I got the same error of yours, and in the same context (a podspec that depends on Moya). What I did was to add Alamofire directly on the podspec. However, this is weird because we didn't have this issue on previous Moya versions 馃

@sunshinejr Although I believe you had renamed the method cases in master by the time this came up, pod specs only allow you to point to releases and the 8.0.0 beta 2 tag/release still had uppercase cases. Either way, I don't think that's the issue.

@marcelofabri I'll give that a shot.

Oh, I will keep this opened till we resolve the issue then :)

@marcelofabri I forgot to report back on this. Following your suggestion of explicitly adding Alamofire to the podspec dependencies seems to have fixed this issue for me.

Closing this now, then. :)

Was this page helpful?
0 / 5 - 0 ratings