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 trial

iOS Network Programming with Swift 2 Implementing a Forecast Client From JSON to CurrentWeather

Type "ForecastAPIClient" not conformingto protocol "APICLient"

I noticed that you did not implement the JSONTaskWithRequest method from the APIClient protocol and I am getting an error.

3 Answers

I had the same problem, so I went through all my code vs the download code with a fine tooth comb and found that in the protocol APIClient, I had a line: init(config: NSURLSessionConfiguration) and the download code did not. I deleted this line, and the error went away.

BEFORE: protocol APIClient { var configuration: NSURLSessionConfiguration { get } var session: NSURLSession { get }

 init(config: NSURLSessionConfiguration) 

func JSONTaskWithRequest(request: NSURLRequest, completion: JSONTaskCompletion) -> JSONTask
func fetch<T: JSONDecodable>(request: NSURLRequest, parse: JSON -> T?, completion: APIResult<T> -> Void)

}

AFTER: protocol APIClient { var configuration: NSURLSessionConfiguration { get } var session: NSURLSession { get }

func JSONTaskWithRequest(request: NSURLRequest, completion: JSONTaskCompletion) -> JSONTask
func fetch<T: JSONDecodable>(request: NSURLRequest, parse: JSON -> T?, completion: APIResult<T> -> Void)

}

Anthony Boutinov
Anthony Boutinov
13,844 Points

In my code, I forgot to add protocol conformance to T in fetch method in the protocol declaration (only added this bit to the default implementation which meant that those two methods weren't the same and so ForecastAPIClient was missing fetch method)

protocol APIClient {
   ...
   func fetch<T: JSONDecodable>( ...
Keenan Turner
Keenan Turner
6,270 Points

Richard Ni were you able to find an answer to this problem? I'm having the same issue, and when I run the program the compiler is telling me is that the ForecastAPIClient is not conforming to the APIClient because I do not have an implementation of this method:

func JSONTaskWithRequest(request: URLRequest, completion: JSONTaskCompletion) -> JSONTask

I've ran through the videos up and down, and am not getting close to the answer. I thought the fetch method handled this task...