November 2018
Intermediate to advanced
404 pages
10h 16m
English
The editEntry(entry:) function creates a new URLSession task to upload the JSON object of the newly-updated JournalEntry object to the web application:
// Edit an existing entryfunc editEntry(entry: JournalEntry) { print("INFO: Receiving modified entry: \(entry)") guard let jsonData = try? JSONEncoder().encode(entry) else { return } guard let id = entry.id else { print("Error: Invalid ID") return } let idString : String = "/admin/\(id)" let journalUrl = URL(string: apiURL + idString)! var request = URLRequest(url: journalUrl) request.httpMethod = "PUT" request.setValue("application/json", forHTTPHeaderField: "Content-Type") URLSession.shared.uploadTask(with: request, from: jsonData) { (data, response, error) in ...Read now
Unlock full access