Skip to content

Commit 13c2468

Browse files
committed
Add source code for appendix C
1 parent 523b8bf commit 13c2468

File tree

91 files changed

+4611
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4611
-0
lines changed

19-appendix-c-uikit/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#### joe made this: https://goel.io/joe
2+
3+
#####=== Swift ===#####
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# CocoaPods
25+
#
26+
# We recommend against adding the Pods directory to your .gitignore. However
27+
# you should judge for yourself, the pros and cons are mentioned at:
28+
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
29+
#
30+
# Pods/
31+

19-appendix-c-uikit/Albertos.xcodeproj/project.pbxproj

Lines changed: 1595 additions & 0 deletions
Large diffs are not rendered by default.

19-appendix-c-uikit/Albertos.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.
Lines changed: 8 additions & 0 deletions
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>

19-appendix-c-uikit/Albertos.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1230"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
18+
BuildableName = "Albertos.app"
19+
BlueprintName = "Albertos"
20+
ReferencedContainer = "container:Albertos.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES"
31+
onlyGenerateCoverageForSpecifiedTargets = "YES">
32+
<CodeCoverageTargets>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
36+
BuildableName = "Albertos.app"
37+
BlueprintName = "Albertos"
38+
ReferencedContainer = "container:TheItalianRestaurant.xcodeproj">
39+
</BuildableReference>
40+
</CodeCoverageTargets>
41+
<Testables>
42+
<TestableReference
43+
skipped = "NO">
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "3FC9D8BD2562389F00BF115D"
47+
BuildableName = "AlbertosTests.xctest"
48+
BlueprintName = "AlbertosTests"
49+
ReferencedContainer = "container:Albertos.xcodeproj">
50+
</BuildableReference>
51+
</TestableReference>
52+
<TestableReference
53+
skipped = "YES">
54+
<BuildableReference
55+
BuildableIdentifier = "primary"
56+
BlueprintIdentifier = "3FC9D8C8256238A000BF115D"
57+
BuildableName = "AlbertosUITests.xctest"
58+
BlueprintName = "AlbertosUITests"
59+
ReferencedContainer = "container:Albertos.xcodeproj">
60+
</BuildableReference>
61+
</TestableReference>
62+
</Testables>
63+
</TestAction>
64+
<LaunchAction
65+
buildConfiguration = "Debug"
66+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
67+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
68+
launchStyle = "0"
69+
useCustomWorkingDirectory = "NO"
70+
ignoresPersistentStateOnLaunch = "NO"
71+
debugDocumentVersioning = "YES"
72+
debugServiceExtension = "internal"
73+
allowLocationSimulation = "YES">
74+
<BuildableProductRunnable
75+
runnableDebuggingMode = "0">
76+
<BuildableReference
77+
BuildableIdentifier = "primary"
78+
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
79+
BuildableName = "Albertos.app"
80+
BlueprintName = "Albertos"
81+
ReferencedContainer = "container:Albertos.xcodeproj">
82+
</BuildableReference>
83+
</BuildableProductRunnable>
84+
</LaunchAction>
85+
<ProfileAction
86+
buildConfiguration = "Release"
87+
shouldUseLaunchSchemeArgsEnv = "YES"
88+
savedToolIdentifier = ""
89+
useCustomWorkingDirectory = "NO"
90+
debugDocumentVersioning = "YES">
91+
<BuildableProductRunnable
92+
runnableDebuggingMode = "0">
93+
<BuildableReference
94+
BuildableIdentifier = "primary"
95+
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
96+
BuildableName = "Albertos.app"
97+
BlueprintName = "Albertos"
98+
ReferencedContainer = "container:Albertos.xcodeproj">
99+
</BuildableReference>
100+
</BuildableProductRunnable>
101+
</ProfileAction>
102+
<AnalyzeAction
103+
buildConfiguration = "Debug">
104+
</AnalyzeAction>
105+
<ArchiveAction
106+
buildConfiguration = "Release"
107+
revealArchiveInOrganizer = "YES">
108+
</ArchiveAction>
109+
</Scheme>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct AlertViewModel {
2+
3+
let title: String
4+
let message: String
5+
let buttonText: String
6+
let buttonAction: (() -> Void)?
7+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import Combine
2+
import UIKit
3+
4+
class AppCoordinator: MenuListViewControllerNavigationDelegate, OrderDetailViewControllerDelegate {
5+
6+
let navigationController: UINavigationController
7+
private let orderController: OrderController
8+
private let paymentProcessing: PaymentProcessing
9+
10+
private lazy var menuListViewController: MenuListViewController = {
11+
let viewController = MenuListViewController(menuFetching: MenuFetcher())
12+
viewController.navigationDelegate = self
13+
return viewController
14+
}()
15+
16+
private let orderButton: UIButton
17+
18+
private lazy var orderButtonViewModel = OrderButtonViewModel(orderController: orderController)
19+
20+
private var cancellables = Set<AnyCancellable>()
21+
22+
init(
23+
orderController: OrderController,
24+
paymentProcessing: PaymentProcessing,
25+
navigationController: UINavigationController = UINavigationController()
26+
) {
27+
self.navigationController = navigationController
28+
self.orderController = orderController
29+
self.paymentProcessing = paymentProcessing
30+
31+
orderButton = BigButton() // a `UIButton` subclass that configures the button style
32+
33+
orderButtonViewModel.$text
34+
.sink { [weak self] text in
35+
guard let button = self?.orderButton else { return }
36+
button.setTitle(text, for: .normal)
37+
}
38+
.store(in: &cancellables)
39+
40+
orderButton.addAction(
41+
UIAction(handler: { [weak self] _ in self?.presentOrderDetail()}),
42+
for: .primaryActionTriggered
43+
)
44+
}
45+
46+
func loadFirstScreen() {
47+
navigationController.viewControllers = [menuListViewController]
48+
49+
navigationController.view.addSubview(orderButton)
50+
51+
orderButton.pin(.centerX, to: navigationController.view)
52+
orderButton.alignSafeAreaBottomAnchor(to: navigationController.view)
53+
}
54+
55+
func orderDetailViewControllerCompletedPaymentFlow(_ viewController: OrderDetailViewController) {
56+
navigationController.dismiss(animated: true, completion: .none)
57+
}
58+
59+
func menuListViewController(
60+
_ viewController: MenuListViewController,
61+
didSelectItem item: MenuItem
62+
) {
63+
navigationController.pushViewController(
64+
MenuItemDetailViewController(
65+
viewModel: .init(item: item, orderController: orderController)
66+
),
67+
animated: true
68+
)
69+
}
70+
71+
func presentOrderDetail() {
72+
let orderDetailViewController = OrderDetailViewController(
73+
orderController: orderController,
74+
paymentProcessor: paymentProcessing
75+
)
76+
orderDetailViewController.delegate = self
77+
78+
navigationController.present(
79+
UINavigationController(rootViewController: orderDetailViewController),
80+
animated: true,
81+
completion: .none
82+
)
83+
}
84+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import UIKit
2+
3+
@main
4+
class AppDelegate: UIResponder, UIApplicationDelegate {
5+
6+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
7+
return true
8+
}
9+
10+
// MARK: - UISceneSession Lifecycle
11+
12+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
13+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}

0 commit comments

Comments
 (0)