Moya: Build error related to NSURL optionals in Swift 2.3

Created on 14 Sep 2016  路  12Comments  路  Source: Moya/Moya

I have recently updated to Xcode 8 and attempted to convert my existing projects to Swift 2.3. Even though I updated Moya to 7.0.1 through CocoaPods, the following build error persists from the following Moya source code (as a part of the extension of MoyaProvider): Value of optional type 'NSURL?' not unwrapped; did you mean to use '!' or '?'?

public final class func DefaultEndpointMapping(target: Target) -> Endpoint<Target> {
    let url = target.baseURL.URLByAppendingPathComponent(target.path).absoluteString
    return Endpoint(URL: url, sampleResponseClosure: {.NetworkResponse(200, target.sampleData)}, method: target.method, parameters: target.parameters)
}

Hope this can be resolved soon. Thanks very much!

bug?

All 12 comments

@ashfurrow Hi, I'm investigating this issue for also me.
There is release-7.0.1 branch, and also there is 7.0.1 tag. However, that tag is tagged at the same commit which is tagged name specified as 7.0.0.
That branch is working in Swift2.3, I know. Perhaps, is that tag your mistake? if so, I want you to tag 7.0.1 on release-7.0.1 branch.

Thanks.

Hey, 7.0.1 is tagged at the same commit as 7.0.0, but that's was a conscious decision
Details here: https://github.com/Moya/Moya/pull/594#issuecomment-246513882

Yup, it was caused by a mistake on my part, working to fix it and release Moya with Swift 2.3 compatibility today.

This should be fixed now, could you try updating to Moya 7.0.2 and letting us know if it works?

I still get the error. Seem that code was not updated?

Are you using Cocoapods or Carthage? Is the version number 7.0.2?

@BasThomas Yes, i'm using CocoaPods and pod version is 7.0.2. Try to set to 7.0.0 but it still load as 7.0.2?

7.0.2 is what you want for Swift 2.3. Try pod update Moya, without specifying a version in your Podfile. That should install the latest version, which is 7.0.2. Maybe try deleting the Pods directory, if you can, and re-run pod install.

@ashfurrow Looks good after updating to 7.0.2. Thanks the team for your quick response!

Oops, sorry, i'm using XCode 7.3.1/Swift 2.2.
In #631 @ashfurrow told that 7.0.1 is latest version support Swift 2.2.. But i cannot install although i have specific version number in pod, it always get 7.0.2.

This is my pod:

    pod 'Moya', '~> 7.0.0'
    pod 'Moya/RxSwift', '~> 7.0.0'
    pod 'ObjectMapper'
    pod 'Moya-ObjectMapper/RxSwift', '~> 1.3.1'

Here is pod log:

Installing Moya (7.0.2)
Installing Moya-ObjectMapper (1.3.1)
Installing ObjectMapper (1.4.0)

@dangthaison91 You need to explicitly specify that you want Moya 7.0.0. You can do this like:

pod 'Moya/RxSwift', '7.0.0'

(you also don't need both Moya and Moya/RxSwift, because Moya/RxSwift has Moya in it)

You can check here what ~> means and more in a Podfile. Hope it helps!

Thanks @sunshinejr, i used wrong opertor :(. Thanks the team for yours really quick response!

Was this page helpful?
0 / 5 - 0 ratings