-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d05281
commit 5c17384
Showing
26 changed files
with
3,127 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
0234-composable-navigation-pt13/Inventory/COW.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
struct Wrapper<Value> { | ||
var value: Value { | ||
get { self.storage.value } | ||
set { | ||
if Swift.isKnownUniquelyReferenced(&self.storage) { | ||
self.storage.value = newValue | ||
} else { | ||
self.storage = Storage(value: newValue) | ||
} | ||
} | ||
} | ||
|
||
private var storage: Storage | ||
|
||
init(value: Value) { | ||
self.storage = Storage(value: value) | ||
} | ||
|
||
mutating func isKnownUniquelyReferenced() -> Bool { | ||
Swift.isKnownUniquelyReferenced(&self.storage) | ||
} | ||
|
||
private class Storage { | ||
var value: Value | ||
init(value: Value) { | ||
self.value = value | ||
} | ||
} | ||
} | ||
|
||
import Foundation | ||
|
||
extension Wrapper: Equatable where Value: Equatable { | ||
static func == (lhs: Self, rhs: Self) -> Bool { | ||
if lhs.storage === rhs.storage { | ||
return true | ||
} | ||
Thread.sleep(forTimeInterval: 3) | ||
return lhs.value == rhs.value | ||
} | ||
} | ||
|
||
var x = Wrapper(value: 1) | ||
x.isKnownUniquelyReferenced() | ||
var y = x | ||
x.isKnownUniquelyReferenced() | ||
y.isKnownUniquelyReferenced() | ||
x == y | ||
x.value = 2 | ||
y.value = 2 | ||
x == y | ||
y.value | ||
x.value | ||
x.isKnownUniquelyReferenced() | ||
y.isKnownUniquelyReferenced() | ||
|
||
var z = 1 | ||
var w = z | ||
z = 2 | ||
w | ||
z |
4 changes: 4 additions & 0 deletions
4
0234-composable-navigation-pt13/Inventory/COW.playground/contents.xcplayground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='macos'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
570 changes: 570 additions & 0 deletions
570
0234-composable-navigation-pt13/Inventory/Inventory.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...avigation-pt13/Inventory/Inventory.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...3/Inventory/Inventory.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
88 changes: 88 additions & 0 deletions
88
...e-navigation-pt13/Inventory/Inventory.xcodeproj/xcshareddata/xcschemes/Inventory.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1420" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "2A3BE9F22994469500351060" | ||
BuildableName = "Inventory.app" | ||
BlueprintName = "Inventory" | ||
ReferencedContainer = "container:Inventory.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "2A3BEA022994469600351060" | ||
BuildableName = "InventoryTests.xctest" | ||
BlueprintName = "InventoryTests" | ||
ReferencedContainer = "container:Inventory.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 = "2A3BE9F22994469500351060" | ||
BuildableName = "Inventory.app" | ||
BlueprintName = "Inventory" | ||
ReferencedContainer = "container:Inventory.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "2A3BE9F22994469500351060" | ||
BuildableName = "Inventory.app" | ||
BlueprintName = "Inventory" | ||
ReferencedContainer = "container:Inventory.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
11 changes: 11 additions & 0 deletions
11
...le-navigation-pt13/Inventory/Inventory/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...able-navigation-pt13/Inventory/Inventory/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
0234-composable-navigation-pt13/Inventory/Inventory/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
0234-composable-navigation-pt13/Inventory/Inventory/ContentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
struct AppFeature: Reducer { | ||
struct State: Equatable { | ||
var firstTab = FirstTabFeature.State() | ||
var inventory = InventoryFeature.State() | ||
var selectedTab: Tab = .one | ||
var thirdTab = ThirdTabFeature.State() | ||
} | ||
enum Action: Equatable { | ||
case firstTab(FirstTabFeature.Action) | ||
case inventory(InventoryFeature.Action) | ||
case selectedTabChanged(Tab) | ||
case thirdTab(ThirdTabFeature.Action) | ||
} | ||
var body: some ReducerOf<Self> { | ||
Reduce<State, Action> { state, action in | ||
switch action { | ||
case let .firstTab(.delegate(action)): | ||
switch action { | ||
case .switchToInventoryTab: | ||
state.selectedTab = .inventory | ||
return .none | ||
} | ||
|
||
case let .selectedTabChanged(tab): | ||
state.selectedTab = tab | ||
return .none | ||
|
||
case .firstTab, .inventory, .thirdTab: | ||
return .none | ||
} | ||
} | ||
Scope(state: \.firstTab, action: /Action.firstTab) { | ||
FirstTabFeature() | ||
} | ||
Scope(state: \.inventory, action: /Action.inventory) { | ||
InventoryFeature() | ||
} | ||
Scope(state: \.thirdTab, action: /Action.thirdTab) { | ||
ThirdTabFeature() | ||
} | ||
} | ||
} | ||
|
||
enum Tab { | ||
case one, inventory, three | ||
} | ||
|
||
struct ContentView: View { | ||
//@State var selectedTab: Tab = .one | ||
let store: StoreOf<AppFeature> | ||
// Store<AppFeature.State, AppFeature.Action> | ||
|
||
var body: some View { | ||
WithViewStore(self.store, observe: \.selectedTab) { viewStore in | ||
TabView(selection: viewStore.binding(send: AppFeature.Action.selectedTabChanged)) { | ||
FirstTabView( | ||
store: self.store.scope( | ||
state: \.firstTab, | ||
action: AppFeature.Action.firstTab | ||
) | ||
) | ||
.tabItem { Text("One") } | ||
.tag(Tab.one) | ||
|
||
NavigationStack { | ||
InventoryView( | ||
store: self.store.scope( | ||
state: \.inventory, | ||
action: AppFeature.Action.inventory | ||
) | ||
) | ||
} | ||
.tabItem { Text("Inventory") } | ||
.tag(Tab.inventory) | ||
|
||
ThirdTabView( | ||
store: self.store.scope( | ||
state: \.thirdTab, | ||
action: AppFeature.Action.thirdTab | ||
) | ||
) | ||
.tabItem { Text("Three") } | ||
.tag(Tab.three) | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView( | ||
store: Store( | ||
initialState: AppFeature.State(), | ||
reducer: AppFeature() | ||
) | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
0234-composable-navigation-pt13/Inventory/Inventory/FirstTab.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
struct FirstTabFeature: Reducer { | ||
struct State: Equatable {} | ||
enum Action: Equatable { | ||
case goToInventoryButtonTapped | ||
case delegate(Delegate) | ||
|
||
enum Delegate: Equatable { | ||
case switchToInventoryTab | ||
} | ||
} | ||
|
||
func reduce(into state: inout State, action: Action) -> Effect<Action> { | ||
switch action { | ||
case .delegate: | ||
return .none | ||
|
||
case .goToInventoryButtonTapped: | ||
return .send(.delegate(.switchToInventoryTab)) | ||
} | ||
} | ||
} | ||
|
||
struct FirstTabView: View { | ||
let store: StoreOf<FirstTabFeature> | ||
|
||
var body: some View { | ||
WithViewStore(self.store, observe: { $0 }) { viewStore in | ||
Button { | ||
viewStore.send(.goToInventoryButtonTapped) | ||
} label: { | ||
Text("Go to inventory") | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
0234-composable-navigation-pt13/Inventory/Inventory/Info.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?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>NSAppTransportSecurity</key> | ||
<dict> | ||
<key>NSAllowsArbitraryLoads</key> | ||
<true/> | ||
</dict> | ||
</dict> | ||
</plist> |
Oops, something went wrong.