Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJo Lingenfelter
Treehouse Project ReviewerProtocol requires function JSONTaskWithRequest with type...Do you want to add a stub?
Using Swift 3, I'm getting an error that FoursquareClient does not conform to protocol APIClient and being asked if I want to create a stub. I downloaded the project and converted it to Swift 3, and it's having the same issue. Does anyone know how to fix this?
2 Answers
Jo Lingenfelter
Treehouse Project ReviewerI just took those methods out of the protocol and left them in the extension. It works fine after that.
tecastecs
Full Stack JavaScript Techdegree Student 5,090 PointsHow you fix that ?
Chris Smith
6,791 PointsYeah I've done the same tecastecs. Basically I removed the JSONTaskWithRequest & Fetch methods from the APIClient Protocol (that were outside of the protocol extension). However, these methods remain in the APIClient protocol extension. This will remove the error.
protocol APIClient {
var configuration: URLSessionConfiguration { get }
var session: URLSession { get }
}
Roger Antonell
18,252 PointsThis problem happens because the APIClient protocol have different "JSONTaskWithRequest" and "fetch" functions signature, than the signature that you provided via extension , if you check the signature of the functions in the protocol declaration and the extension, you will see that they are different, here is how they have to look:
protocol APIClient {
var configuration: URLSessionConfiguration { get }
var session: URLSession { get }
func JSONTaskWithRequest(_ request: URLRequest, completion: @escaping JSONCompletion) -> JSONTask
func fetch<T: JSONDecodable>(_ request: URLRequest, parse: @escaping (JSON) -> T?, completion: @escaping (APIResult<T>) -> Void)
}
extension APIClient {
func JSONTaskWithRequest(_ request: URLRequest, completion: @escaping JSONCompletion) -> JSONTask {...}
func fetch<T>(_ request: URLRequest, parse: @escaping (JSON) -> T?, completion: @escaping (APIResult<T>) -> Void) {...}
func fetch<T>(enpoint: Endpoint, parse: @escaping (JSON) -> [T]?, completion: @escaping (APIResult<[T]>) -> Void) {...}
Roger Antonell
18,252 PointsThis problem happens because the APIClient protocol have different "JSONTaskWithRequest" and "fetch" functions signature, than the signature that you provided via extension , if you check the signature of the functions in the protocol declaration and the extension, you will see that they are different, here is how they have to look:
protocol APIClient {
var configuration: URLSessionConfiguration { get }
var session: URLSession { get }
func JSONTaskWithRequest(_ request: URLRequest, completion: @escaping JSONCompletion) -> JSONTask
func fetch<T: JSONDecodable>(_ request: URLRequest, parse: @escaping (JSON) -> T?, completion: @escaping (APIResult<T>) -> Void)
}
extension APIClient {
func JSONTaskWithRequest(_ request: URLRequest, completion: @escaping JSONCompletion) -> JSONTask {...}
func fetch<T>(_ request: URLRequest, parse: @escaping (JSON) -> T?, completion: @escaping (APIResult<T>) -> Void) {...}
func fetch<T>(enpoint: Endpoint, parse: @escaping (JSON) -> [T]?, completion: @escaping (APIResult<[T]>) -> Void) {...}
eberhapa
51,495 Pointseberhapa
51,495 PointsSame problem. Anyone?