November 2018
Intermediate to advanced
404 pages
10h 16m
English
After learning the basics for creating an uploading task, you can assemble the newEntry(entry:) function:
// Create a new entryfunc newEntry(entry: JournalEntry) {// prepare JSON data to uploadguard let jsonData = try? JSONEncoder().encode(entry) else { return }// configure URL requestlet journalUrl = URL(string: apiURL + "/admin")!var request = URLRequest(url: journalUrl)request.httpMethod = "POST"request.setValue("application/json", forHTTPHeaderField: "Content-Type")// Start an URLSession TaskURLSession.shared.uploadTask(with: request, from: jsonData) { (data, response, error) in if let error = error { print("Error", error) return } }.resume()}
Try to edit a journal entry now. The corresponding ...
Read now
Unlock full access