Skip to content

Commit e35448d

Browse files
committed
Use a more modern app example
1 parent 7c1dea0 commit e35448d

File tree

10 files changed

+157
-385
lines changed

10 files changed

+157
-385
lines changed

Examples/LocalDebugging/MyApp/MyApp.xcodeproj/project.pbxproj

Lines changed: 86 additions & 87 deletions
Large diffs are not rendered by default.

Examples/LocalDebugging/MyApp/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Examples/LocalDebugging/MyApp/MyApp.xcodeproj/xcshareddata/xcschemes/MyApp.xcscheme

Lines changed: 0 additions & 78 deletions
This file was deleted.

Examples/LocalDebugging/MyApp/MyApp/AppDelegate.swift

Lines changed: 0 additions & 37 deletions
This file was deleted.

Examples/LocalDebugging/MyApp/MyApp/Base.lproj/LaunchScreen.storyboard

Lines changed: 0 additions & 25 deletions
This file was deleted.

Examples/LocalDebugging/MyApp/MyApp/ContentView.swift

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftAWSLambdaRuntime open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
5+
// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -19,31 +19,40 @@ struct ContentView: View {
1919
@State var name: String = ""
2020
@State var password: String = ""
2121
@State var response: String = ""
22+
@State private var isLoading: Bool = false
2223

2324
var body: some View {
2425
VStack(alignment: .leading, spacing: 20) {
2526
TextField("Username", text: $name)
2627
SecureField("Password", text: $password)
27-
Button(
28-
action: {
29-
Task {
30-
await self.register()
31-
}
32-
},
33-
label: {
34-
Text("Register")
35-
.padding()
36-
.foregroundColor(.white)
37-
.background(Color.black)
38-
.border(Color.black, width: 2)
28+
let buttonDisabled = name.isEmpty || password.isEmpty
29+
Button {
30+
Task {
31+
isLoading = true
32+
response = await register()
33+
isLoading = false
3934
}
40-
)
35+
} label: {
36+
Text("Register")
37+
.padding()
38+
.foregroundColor(.white)
39+
.background(.black)
40+
.border(.black, width: 2)
41+
.opacity(isLoading ? 0 : 1)
42+
.overlay {
43+
if isLoading {
44+
ProgressView()
45+
}
46+
}
47+
}
48+
.disabled(buttonDisabled)
49+
.opacity(buttonDisabled ? 0.5 : 1)
4150
Text(response)
4251
}.padding(100)
4352
}
4453

45-
func register() async {
46-
guard let url = URL(string: "http://127.0.0.1:7000/invoke") else {
54+
func register() async -> String {
55+
guard let url = URL(string: "http://localhost:9001/invoke") else {
4756
fatalError("invalid url")
4857
}
4958
var request = URLRequest(url: url)
@@ -55,25 +64,19 @@ struct ContentView: View {
5564
request.httpBody = jsonRequest
5665

5766
do {
58-
let (data, response) = try await URLSession.shared.data(for: request)
67+
let (data, urlResponse) = try await URLSession.shared.data(for: request)
5968

60-
guard let httpResponse = response as? HTTPURLResponse else {
61-
throw CommunicationError(reason: "invalid response, expected HTTPURLResponse")
69+
guard let httpResponse = urlResponse as? HTTPURLResponse else {
70+
return "invalid response, expected HTTPURLResponse"
6271
}
6372
guard httpResponse.statusCode == 200 else {
64-
throw CommunicationError(reason: "invalid response code: \(httpResponse.statusCode)")
73+
return "invalid response code: \(httpResponse.statusCode)"
6574
}
66-
let jsonResponse = try JSONDecoder().decode(Response.self, from: data)
6775

68-
self.response = jsonResponse.message
76+
let response = try JSONDecoder().decode(Response.self, from: data)
77+
return response.message
6978
} catch {
70-
self.response = error.localizedDescription
71-
}
72-
}
73-
74-
func setResponse(_ text: String) {
75-
DispatchQueue.main.async {
76-
self.response = text
79+
return error.localizedDescription
7780
}
7881
}
7982
}
@@ -83,7 +86,3 @@ struct ContentView_Previews: PreviewProvider {
8386
ContentView()
8487
}
8588
}
86-
87-
struct CommunicationError: Error {
88-
let reason: String
89-
}

Examples/LocalDebugging/MyApp/MyApp/Info.plist

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import SwiftUI
16+
17+
@main
18+
struct MyApp: App {
19+
var body: some Scene {
20+
WindowGroup {
21+
ContentView()
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)