I'm a newbie in creating an sign in using API in swift. I followed a video tutorial from treehouse but I used different version of Xcode and swift. I don't know what will I put in these code. Hope you could help me Or can you give me any references that I could use in creating a sign in page that will input passcode in textfield and submit to validate if the code is existing and will post data. Thank you so much.
When I click Fix these line of code appeared
final class EventAPIClient: APIService {
func JSONTaskWithRequest(request: URLRequest, completion: (JSON?, HTTPURLResponse?, NSError?) -> Void) -> JSONTask {
<#code#>
}
init(config: URLSessionConfiguration) {
<#code#>
}
let configuration: URLSessionConfiguration
lazy var session: URLSession = {
return URLSession(configuration: self.configuration)
}()
private let token: String
init(config: URLSessionConfiguration, APIKey: String) {
self.configuration = config
self.token = APIKey
}
convenience init(APIKey: String) {
self.init(config: URLSessionConfiguration.default, APIKey: APIKey)
}
}
In order to begin to resolve this issue, you need to look at what protocols are.
Focusing on information relevant to this situation, they essentially define the signature of a function (among other things). The name of the protocol and the function signature leave clues as to what a given function's implementation should be. This is easily illustrated by a simple example:
tying it back into your situation. The protocol
APIService
has defined the functions like so:Your
EventAPIClient
class tells the compiler it means to conform to theAPIService
protocol:In order to conform to the protocol,
EventAPIClient
needs to provide an implementation for all the definitions inAPIService
.As for solving the issue, there are some missing pieces of information regarding the definition of JSONTask etc. However, here is an example implementation that should, if nothing else, give you a starting point:
I hope you find this helpful :)