Swift
Control Rclone from Swift using the remote control HTTP API with URLSession.
Swift's URLSession provides a powerful and native way to make HTTP requests to Rclone's remote control API on Apple platforms.
Usage
import Foundation
let url = URL(string: "http://localhost:5572/")!
let task = URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let data = data, let body = String(data: data, encoding: .utf8) {
print(body)
}
}
task.resume()
// Keep the program running for async task
RunLoop.main.run()Using async/await (iOS 15+, macOS 12+):
import Foundation
Task {
let url = URL(string: "http://localhost:5572/")!
let (data, _) = try await URLSession.shared.data(from: url)
if let body = String(data: data, encoding: .utf8) {
print(body)
}
}How is this guide?