https://github.com/zunda-pixel/sharing-firebase
https://github.com/zunda-pixel/sharing-firebase
swift
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/zunda-pixel/sharing-firebase
- Owner: zunda-pixel
- License: apache-2.0
- Created: 2025-03-29T15:32:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-31T14:32:53.000Z (about 1 year ago)
- Last Synced: 2025-03-31T15:34:05.699Z (about 1 year ago)
- Topics: swift
- Language: Swift
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SharingFirebase
SharingFirebase uses [swift-sharing](https://github.com/pointfreeco/swift-sharing) and [firebase-swift](https://github.com/zunda-pixel/firebase-swift)
[](https://swiftpackageindex.com/zunda-pixel/sharing-firebase)
[](https://swiftpackageindex.com/zunda-pixel/sharing-firebase)
## SharingRemoteConfig
```swift
struct ContentView: View {
@SharedReader(.remoteConfig("parameterBool")) var parameterBoolString: String?
@SharedReader(.remoteConfig("parameterInt")) var parameterIntString: String?
@SharedReader(.remoteConfig("parameterString")) var parameterString: String?
@SharedReader(.remoteConfig("parameterJson")) var parameterJsonString: String?
var parameterInt: Int? {
parameterIntString.flatMap { Int($0) }
}
var parameterBool: Bool? {
parameterBoolString.flatMap { try? JSONDecoder().decode(Bool.self, from: Data($0.utf8)) }
}
var parameterJson: User? {
parameterJsonString.flatMap { try? JSONDecoder().decode(User.self, from: Data($0.utf8)) }
}
var body: some View {
VStack {
Text("String: \(parameterString ?? "Nothing")")
Text("Int: \(parameterInt?.description ?? "Nothing")")
Text("Bool: \(parameterBool?.description ?? "Nothing")")
Text("User.name: \(parameterJson?.name ?? "Nothing")")
Text("User.age: \(parameterJson?.age.description ?? "Nothing")")
}
}
}
#Preview {
ContentView()
.frame(maxWidth: 500, maxHeight: 500)
}
struct User: Decodable {
var name: String
var age: Int
}
extension SharedReaderKey {
static func remoteConfig(_ key: String) -> Self
where Self == RemoteConfigValueKey {
RemoteConfigValueKey(key: key, client: .sampleProject)
}
}
extension RemoteConfigClient {
static let sampleProject = RemoteConfigClient(
apiKey: "AIzaSyCI6lc5~~~~~~~~m4ZQ9PoL5oVtM",
projectId: "21~~~~~289",
projectName: "n~~~~s",
appId: "1:2~~~~~~289:ios:1~~~~~~~~~d5d8",
appInstanceId: UUID().uuidString,
httpClient: .urlSession(.shared)
)
}
```