How to Finish Editing a Document in Swift

Cloudmersive
1 min readAug 6, 2021

In the previous tutorial, we demonstrated how you can open up a document for various editing operations in Swift, and in this tutorial, we will show you how you can close things out. After you have completed the changes to your document, you can use the following API to call the finish editing function and download your updated result.

All you will need is your API key and the editing URL that was generated in the begin-editing process to input into the below example code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)let parameters = "InputFileUrl=%3Cstring%3E"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/convert/edit/finish-editing")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()

At the end of this quick operation, you will receive your downloadable document. To retrieve an API key, visit the Cloudmersive website and register for a free account; this provides 800 monthly calls across our multitude of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.