Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Compile error: direct generic type metadata pattern for Result.Result #81

Closed
nRewik opened this issue Sep 19, 2015 · 5 comments
Closed

Comments

@nRewik
Copy link

nRewik commented Sep 19, 2015

I use BrightFutures with Alamofire

I write extension for Alamofire.Request.

request.responseJSONPromise() run with no error.

However, when I chain Future using flatMap, Xcode7 shows a compile error message.

screen shot 2558-09-19 at 15 54 40

Here's my code

public func getToken(username username: String, password: String) -> Future<String, DRCloudServerError> {

    let request = Alamofire.request( .POST, url, parameters: params)

    return request.responseJSONPromise().flatMap{ json -> Future<String, DRCloudServerError> in

        let promise = Promise<String, DRCloudServerError>()
        if let accessToken = json["access_token"].string{
            promise.trySuccess(accessToken)
        }else{
            promise.tryFailure(DRCloudServerError.JSONParseError)
        }
        return promise.future
    }
}

and my Alamofire.Request extension

extension Alamofire.Request{

    func responseJSONPromise() -> Future<JSON,DRCloudServerError>{

        let promise = Promise<JSON, DRCloudServerError>()
        responseJSON{ request, response, result in

            if let error = self.handleStatusCodeError(response, data: result.data){
                promise.tryFailure(error)
            }

            switch(result){
            case let .Failure(_, error):
                let errorDescription = "\(error)"
                promise.tryFailure(DRCloudServerError.RequestError(errorDescription))
            case let .Success(value):
                let json = JSON(value)
                promise.trySuccess(json)
            }
        }
        return promise.future
    }
}
@Thomvis
Copy link
Owner

Thomvis commented Sep 20, 2015

Hi and sorry to hear you're having problems using BrightFutures.

Can you try rewriting the implementation of getToken, e.g. splitting up parts of the expression and adding more type info? It sounds like a limitation of the compiler to me, which you can try to work around by rewriting expressions and/or adding more type info.

@nRewik
Copy link
Author

nRewik commented Sep 21, 2015

Thank you @Thomvis . I've tried to split up the code and add more type info. Xcode still shows me the same message.

However, I write the same code in the new project with same Podfile, then it works.

I really have no Idea what's happened.

@levous
Copy link

levous commented Dec 3, 2015

I am getting the same compiler error.

Undefined symbols for architecture x86_64:
  "direct generic type metadata pattern for Result.Result", referenced from:
      type metadata accessor for Result.Result<Swift.Bool, After.LovableError> in VibeDetailViewController.o
      type metadata accessor for Result.Result<(loved : Swift.Bool, lovedByCount : Swift.Int), After.LovableError> in VibeDetailViewController.o

I have no clue what that means :-/

@ostap0207
Copy link

Having the same problem. I use BrightFutures + Alamofire. As a workaround added import Result, which solved the problem. But would be good to have proper solution.

@athensholloway
Copy link

I was having the same issue when chaining promises in my view controller. I solved the problem by adding import Result as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants