Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Sharing/SharedReaderKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ extension SharedReader {
///
/// - Parameter key: A shared key associated with the shared reference. It is responsible for
/// loading the shared reference's value from some external source.
@_disfavoredOverload
public init<Wrapped>(_ key: some SharedReaderKey<Value>) where Value == Wrapped? {
self.init(wrappedValue: nil, key)
}

@_disfavoredOverload
@_documentation(visibility: private)
public init<Wrapped>(_ key: some SharedKey<Value>) where Value == Wrapped? {
self.init(key)
self.init(wrappedValue: nil, key)
}

/// Creates a shared reference to a read-only value using a shared key with a default value.
Expand Down
12 changes: 12 additions & 0 deletions Tests/SharingTests/CompileTimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ func testSharedReaderLoadOverload() async throws {
try await shared.load(.count)
}

func testSharedReaderKeyWithDefault() {
@SharedReader(.count)
var count1
@Shared(.count) var count2
}

extension SharedKey where Self == InMemoryKey<Int> {
fileprivate static var count: Self {
.inMemory("count")
}
}

extension SharedReaderKey where Self == AppStorageKey<Int?>.Default {
public static var count: Self {
Self[.appStorage("count"), default: nil]
}
}
Loading