From 29b94be1fa1781b34bbf186b85ffff0ceba1be80 Mon Sep 17 00:00:00 2001 From: sosloan Date: Wed, 22 Jan 2025 04:22:58 -0800 Subject: [PATCH] Add Sandbox API call to the app Add a new function to make a network request and call it from a button. * **ContentView.swift** - Add `callSandboxAPI` function to make a network request to a specified URL. - Add a button to call the `callSandboxAPI` function. --- StudyHallOrg/ContentView.swift | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/StudyHallOrg/ContentView.swift b/StudyHallOrg/ContentView.swift index 15a7935..6737702 100644 --- a/StudyHallOrg/ContentView.swift +++ b/StudyHallOrg/ContentView.swift @@ -51,6 +51,30 @@ struct ContentView: View { } } } + + private func callSandboxAPI() { + guard let url = URL(string: "https://sandbox.api.example.com/endpoint") else { + print("Invalid URL") + return + } + + let task = URLSession.shared.dataTask(with: url) { data, response, error in + if let error = error { + print("Error: \(error)") + return + } + + guard let data = data else { + print("No data received") + return + } + + // Process the data + print("Data received: \(data)") + } + + task.resume() + } } #Preview {