Reputation: 11
I have the following function
func refreshFeedItems(completion: @escaping ActivityFeedCompletion) {
let currentTab = feedTab
//Result<([FeedItem], Bool)>) -> Void
// Load the cache in and start the spinner for the network request we're about to make
completion(.success(cache[currentTab], true))
ActivityFeedService.sharedInstance.refreshCommunityFeed(tab: currentTab) { result in
// A quick user might switch tabs before this
// call completes since we call completion twice
guard currentTab == self.feedTab else {
return
}
switch result {
case .failure(let error):
Log.warn(error)
completion(.failure(error))
case .success(let items):
self.cache[self.feedTab] = items
let tuple = Result.success(items,true) as ActivityFeedCompletion
completion((tuple,false))
}
}
}
But this line
completion(.success(cache[currentTab], true))
and this one
let tuple = Result.success(items,true) as ActivityFeedCompletion
Both throw me an "Extra argument in call" error.
This is my acticvity completion typealias
typealias ActivityFeedCompletion = (Result<([FeedItem], Bool)>) -> Void
I am not sure why I am getting that error, I think it is misleading but I ran out of ideas of what to do to fix it.
Upvotes: 0
Views: 1298
Reputation: 47886
You are hiding many relevant parts of your code, so I needed to fill many parts by guess. If my answer is far from what you expect, you should better update your question and show relevant parts of your code. For example, whole definition of your ActivityFeedCache
.
With this definition:
typealias ActivityFeedCompletion = (Result<([FeedItem], Bool)>) -> Void
The success case of the Result
of your ActivityFeedCompletion
takes a single argument of tuple type ([FeedItem], Bool)
.
In this line:
completion(.success(cache[currentTab], true))
You are passing two arguments, to success
, so the message is clear enough. You need to pass a single argument.
completion(.success((cache[currentTab], true)))
And the latter part:
let tuple = Result.success(items,true) as ActivityFeedCompletion
completion((tuple,false))
You are completely mistaking the types. Result
cannot be converted to ActivityFeedCompletion
, and you cannot pass a raw tuple (tuple,false)
to completion
which takes Result<([FeedItem], Bool)>
.
Please try something like this:
completion(.success((items, true/* or false, which you want to pass? */)))
Upvotes: 0
Reputation: 285082
The second error is pretty clear (the bridge cast is most likely redundant)
let tuple = Result.success(items,true) // as ActivityFeedCompletion
represents already the result so you have to write
completion(tuple)
The first error is probably something similar, it's unclear what cache
is
Upvotes: 1