Skip to content

Commit 50e6388

Browse files
committed
👽️ Update chapter 15 for iOS 16
1 parent 77e66eb commit 50e6388

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@
337337
CODE_SIGN_STYLE = Automatic;
338338
CURRENT_PROJECT_VERSION = 1;
339339
DEVELOPMENT_ASSET_PATHS = "\"WordBrowser/Preview Content\"";
340-
DEVELOPMENT_TEAM = YGAZHQXHH4;
340+
DEVELOPMENT_TEAM = "";
341341
ENABLE_PREVIEWS = YES;
342342
GENERATE_INFOPLIST_FILE = YES;
343343
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
344344
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
345345
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
346346
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
347347
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
348-
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
348+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
349349
LD_RUNPATH_SEARCH_PATHS = (
350350
"$(inherited)",
351351
"@executable_path/Frameworks",
@@ -367,15 +367,15 @@
367367
CODE_SIGN_STYLE = Automatic;
368368
CURRENT_PROJECT_VERSION = 1;
369369
DEVELOPMENT_ASSET_PATHS = "\"WordBrowser/Preview Content\"";
370-
DEVELOPMENT_TEAM = YGAZHQXHH4;
370+
DEVELOPMENT_TEAM = "";
371371
ENABLE_PREVIEWS = YES;
372372
GENERATE_INFOPLIST_FILE = YES;
373373
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
374374
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
375375
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
376376
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
377377
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
378-
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
378+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
379379
LD_RUNPATH_SEARCH_PATHS = (
380380
"$(inherited)",
381381
"@executable_path/Frameworks",

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser/Views/AddWordView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct AddWordView: View {
4242

4343
struct AddWordView_Previews: PreviewProvider {
4444
static var previews: some View {
45-
NavigationView {
45+
NavigationStack {
4646
AddWordView { word in
4747
print(word)
4848
}

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser/Views/LibraryView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import Combine
2323
//
2424
// To resolve this issue, we only mark the functions that actually make changes to published properties
2525
// using @MainActor.
26+
//
27+
// Change for Swift 5.7 / Xcode 14: This has been fixed, and it's now possible to initialise an ObservableObject
28+
// that is marked as @MainActor like this:
29+
// @StateObject var viewModel = WordDetailsViewModel()
30+
//
2631
class LibraryViewModel: ObservableObject {
2732
@Published var searchText = ""
2833
@Published var randomWord = "partially"
@@ -70,6 +75,7 @@ class LibraryViewModel: ObservableObject {
7075
throw WordsAPIError.invalidServerResponse
7176
}
7277
let word = try JSONDecoder().decode(Word.self, from: data)
78+
print("\(#function) is on main thread: \(Thread.isMainThread)")
7379
return word
7480
}
7581
catch {
@@ -103,7 +109,9 @@ struct LibraryView: View {
103109
.searchable(text: $viewModel.searchText)
104110
.autocapitalization(.none)
105111
.refreshable {
112+
print("\(#function) is on main thread BEFORE await: \(Thread.isMainThread)")
106113
await viewModel.refresh()
114+
print("\(#function) is on main thread AFTER await: \(Thread.isMainThread)")
107115
}
108116
.listStyle(.insetGrouped)
109117
.navigationTitle("Library")
@@ -115,7 +123,7 @@ struct LibraryView: View {
115123
}
116124
}
117125
.sheet(isPresented: $isAddNewWordDialogPresented) {
118-
NavigationView {
126+
NavigationStack {
119127
AddWordView { newWord in
120128
viewModel.addFavourite(newWord)
121129
}
@@ -166,7 +174,7 @@ struct LibraryRowView: View {
166174

167175
struct LibraryView_Previews: PreviewProvider {
168176
static var previews: some View {
169-
NavigationView {
177+
NavigationStack {
170178
LibraryView()
171179
}
172180
}

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser/Views/WordDetailsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct WordDetailsView: View {
106106

107107
struct WordDetailsView_Previews: PreviewProvider {
108108
static var previews: some View {
109-
NavigationView {
109+
NavigationStack {
110110
WordDetailsView(word: "Swift")
111111
}
112112
}

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser/Views/WordSearchView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct WordSearchView: View {
101101

102102
struct WordSearchView_Previews: PreviewProvider {
103103
static var previews: some View {
104-
NavigationView {
104+
NavigationStack {
105105
WordSearchView()
106106
}
107107
}

Chapter 15 - Using async await in SwiftUI/WordBrowser/WordBrowser/WordBrowserApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftUI
1111
struct WordBrowserApp: App {
1212
var body: some Scene {
1313
WindowGroup {
14-
NavigationView {
14+
NavigationStack {
1515
LibraryView()
1616
}
1717
}

0 commit comments

Comments
 (0)