Boiler Bill
Boiler Bill

Reputation: 1940

How to call function with named parameter

    public func write<Query: GraphQLQuery>(data: Query.Data, forQuery query: Query) throws {
      try write(object: data, withKey: Query.rootCacheKey, variables: query.variables)
    }

How do I call this function? Several attempts have given me the compiler error: "incorrect argument labels in call (have 'data:forQuery:', expected 'object:withKey:')"

New to swift parameters I guess.

Upvotes: 0

Views: 59

Answers (2)

ManWithBear
ManWithBear

Reputation: 2875

This is generic function that require second parameter (query) to conform GraphQLQuery protocol, which require associated type Data.

I don't know what requirements of this protocol and how it implemented. So let's assume for example:

protocol GraphQLQuery {
    associatedtype Data
}
struct MyQuery: GraphQLQuery {
    typealias Data = Int
}
let query = MyQuery()
try? write(data: 0, forQuery: query)

or

do {
    try write(data: 0, forQuery: query)
} catch { ... error handling }

So now to call function we need pass our query and data this query able to work with (Int in my example)

Upvotes: 1

Joshua
Joshua

Reputation: 503

It looks to me as if, you have an argument in your function that is not defined "forQuery" isn't looking for any values to be passed through when the function is called this may be your problem.

Examples of how you are trying to call the function, would be useful to add to this question just as mentioned in a comment above. Information is a great tool for any developer looking to help answer your question!

Make sure all of your arguments are looking to get a value passed in when calling the function. Example :

public func write<Query: GraphQLQuery>(data: Query.Data, forQuery: pass in forQuery value here query: Query) throws {
      try write(object: data, withKey: Query.rootCacheKey, variables: query.variables)
    }

Upvotes: 0

Related Questions