Skip to content

Commit

Permalink
Add source code for appendix C
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Jul 8, 2021
1 parent 523b8bf commit 13c2468
Show file tree
Hide file tree
Showing 91 changed files with 4,611 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 19-appendix-c-uikit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#### joe made this: https://goel.io/joe

#####=== Swift ===#####

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/

1,595 changes: 1,595 additions & 0 deletions 19-appendix-c-uikit/Albertos.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "682841464136f8c66e04afe5dbd01ab51a3a56f2",
"version": "2.1.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "02b7a39a99c4da27abe03cab2053a9034379639f",
"version": "2.0.0"
}
},
{
"package": "Nimble",
"repositoryURL": "http://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "af1730dde4e6c0d45bf01b99f8a41713ce536790",
"version": "9.2.0"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
BuildableName = "Albertos.app"
BlueprintName = "Albertos"
ReferencedContainer = "container:Albertos.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
BuildableName = "Albertos.app"
BlueprintName = "Albertos"
ReferencedContainer = "container:TheItalianRestaurant.xcodeproj">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8BD2562389F00BF115D"
BuildableName = "AlbertosTests.xctest"
BlueprintName = "AlbertosTests"
ReferencedContainer = "container:Albertos.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8C8256238A000BF115D"
BuildableName = "AlbertosUITests.xctest"
BlueprintName = "AlbertosUITests"
ReferencedContainer = "container:Albertos.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
BuildableName = "Albertos.app"
BlueprintName = "Albertos"
ReferencedContainer = "container:Albertos.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3FC9D8AC2562389E00BF115D"
BuildableName = "Albertos.app"
BlueprintName = "Albertos"
ReferencedContainer = "container:Albertos.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
7 changes: 7 additions & 0 deletions 19-appendix-c-uikit/Albertos/AlertViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct AlertViewModel {

let title: String
let message: String
let buttonText: String
let buttonAction: (() -> Void)?
}
84 changes: 84 additions & 0 deletions 19-appendix-c-uikit/Albertos/AppCoordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import Combine
import UIKit

class AppCoordinator: MenuListViewControllerNavigationDelegate, OrderDetailViewControllerDelegate {

let navigationController: UINavigationController
private let orderController: OrderController
private let paymentProcessing: PaymentProcessing

private lazy var menuListViewController: MenuListViewController = {
let viewController = MenuListViewController(menuFetching: MenuFetcher())
viewController.navigationDelegate = self
return viewController
}()

private let orderButton: UIButton

private lazy var orderButtonViewModel = OrderButtonViewModel(orderController: orderController)

private var cancellables = Set<AnyCancellable>()

init(
orderController: OrderController,
paymentProcessing: PaymentProcessing,
navigationController: UINavigationController = UINavigationController()
) {
self.navigationController = navigationController
self.orderController = orderController
self.paymentProcessing = paymentProcessing

orderButton = BigButton() // a `UIButton` subclass that configures the button style

orderButtonViewModel.$text
.sink { [weak self] text in
guard let button = self?.orderButton else { return }
button.setTitle(text, for: .normal)
}
.store(in: &cancellables)

orderButton.addAction(
UIAction(handler: { [weak self] _ in self?.presentOrderDetail()}),
for: .primaryActionTriggered
)
}

func loadFirstScreen() {
navigationController.viewControllers = [menuListViewController]

navigationController.view.addSubview(orderButton)

orderButton.pin(.centerX, to: navigationController.view)
orderButton.alignSafeAreaBottomAnchor(to: navigationController.view)
}

func orderDetailViewControllerCompletedPaymentFlow(_ viewController: OrderDetailViewController) {
navigationController.dismiss(animated: true, completion: .none)
}

func menuListViewController(
_ viewController: MenuListViewController,
didSelectItem item: MenuItem
) {
navigationController.pushViewController(
MenuItemDetailViewController(
viewModel: .init(item: item, orderController: orderController)
),
animated: true
)
}

func presentOrderDetail() {
let orderDetailViewController = OrderDetailViewController(
orderController: orderController,
paymentProcessor: paymentProcessing
)
orderDetailViewController.delegate = self

navigationController.present(
UINavigationController(rootViewController: orderDetailViewController),
animated: true,
completion: .none
)
}
}
15 changes: 15 additions & 0 deletions 19-appendix-c-uikit/Albertos/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

// MARK: - UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 13c2468

Please sign in to comment.