Skip to content

Commit ea53d29

Browse files
committed
wip
1 parent eb0cc95 commit ea53d29

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
run: make DERIVED_DATA_PATH=~/.derivedData SCHEME="Todos" xcodebuild-raw
114114
- name: VoiceMemos
115115
run: make DERIVED_DATA_PATH=~/.derivedData SCHEME="VoiceMemos" xcodebuild-raw
116-
116+
117117
check-macro-compatibility:
118118
name: Check Macro Compatibility
119119
runs-on: macos-latest

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PLATFORM_WATCHOS = watchOS Simulator,id=$(call udid_for,watchOS,Watch)
1212
PLATFORM = IOS
1313
DESTINATION = platform="$(PLATFORM_$(PLATFORM))"
1414

15+
PLATFORM_ID = $(shell echo "$(DESTINATION)" | sed -E "s/.+,id=(.+)/\1/")
16+
1517
SCHEME = ComposableArchitecture
1618

1719
WORKSPACE = ComposableArchitecture.xcworkspace
@@ -36,11 +38,17 @@ endif
3638

3739
TEST_RUNNER_CI = $(CI)
3840

39-
xcodebuild:
41+
warm-simulator:
42+
@test "$(PLATFORM_ID)" != "" \
43+
&& xcrun simctl boot $(PLATFORM_ID) \
44+
&& open -a Simulator --args -CurrentDeviceUDID $(PLATFORM_ID) \
45+
|| exit 0
46+
47+
xcodebuild: warm-simulator
4048
$(XCODEBUILD)
4149

4250
# Workaround for debugging Swift Testing tests: https://github.com/cpisciotta/xcbeautify/issues/313
43-
xcodebuild-raw:
51+
xcodebuild-raw: warm-simulator
4452
$(XCODEBUILD_COMMAND)
4553

4654
build-for-library-evolution:
@@ -58,7 +66,7 @@ format:
5866
-not -path '*/.*' -print0 \
5967
| xargs -0 swift format --ignore-unparsable-files --in-place
6068

61-
.PHONY: build-for-library-evolution format xcodebuild
69+
.PHONY: build-for-library-evolution format warm-simulator xcodebuild xcodebuild-raw
6270

6371
define udid_for
6472
$(shell xcrun simctl list devices available '$(1)' | grep '$(2)' | sort -r | head -1 | awk -F '[()]' '{ print $$(NF-3) }')

Sources/ComposableArchitecture/SharedState/PersistenceKey/AppStorageKey.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ extension AppStorageKey: PersistenceKey {
291291
) -> Shared<Value>.Subscription {
292292
let previousValue = LockIsolated(initialValue)
293293
let removeObserver: () -> Void
294-
if key.contains(".") {
294+
if key.hasPrefix("@") || key.contains(".") {
295295
let userDefaultsDidChange = NotificationCenter.default.addObserver(
296296
forName: UserDefaults.didChangeNotification,
297297
object: store.wrappedValue,
@@ -318,10 +318,10 @@ extension AppStorageKey: PersistenceKey {
318318
}
319319
removeObserver = { NotificationCenter.default.removeObserver(userDefaultsDidChange) }
320320
} else {
321-
let observer = Observer { newValue in
321+
let observer = Observer {
322322
guard !SharedAppStorageLocals.isSetting
323323
else { return }
324-
didSet(newValue)
324+
didSet(load(initialValue: initialValue))
325325
}
326326
store.wrappedValue.addObserver(observer, forKeyPath: key, options: .new, context: nil)
327327
removeObserver = { store.wrappedValue.removeObserver(observer, forKeyPath: key) }
@@ -345,6 +345,22 @@ extension AppStorageKey: PersistenceKey {
345345
}
346346
}
347347
}
348+
349+
private class Observer: NSObject {
350+
let didChange: () -> Void
351+
init(didChange: @escaping () -> Void) {
352+
self.didChange = didChange
353+
super.init()
354+
}
355+
override func observeValue(
356+
forKeyPath keyPath: String?,
357+
of object: Any?,
358+
change: [NSKeyValueChangeKey: Any]?,
359+
context: UnsafeMutableRawPointer?
360+
) {
361+
self.didChange()
362+
}
363+
}
348364
}
349365

350366
private struct AppStorageKeyID: Hashable {

Sources/ComposableArchitecture/SharedState/PersistenceKey/AppStorageKeyPathKey.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,6 @@ extension AppStorageKeyPathKey: PersistenceKey, Hashable {
6060
observer.invalidate()
6161
}
6262
}
63-
64-
private class Observer: NSObject {
65-
let didChange: (Value?) -> Void
66-
init(didChange: @escaping (Value?) -> Void) {
67-
self.didChange = didChange
68-
super.init()
69-
}
70-
override func observeValue(
71-
forKeyPath keyPath: String?,
72-
of object: Any?,
73-
change: [NSKeyValueChangeKey: Any]?,
74-
context: UnsafeMutableRawPointer?
75-
) {
76-
self.didChange(change?[.newKey] as? Value)
77-
}
78-
}
7963
}
8064

8165
// NB: This is mainly used for tests, where observer notifications can bleed across cases.

0 commit comments

Comments
 (0)