Skip to content

Commit

Permalink
Merge pull request #19 from fumito-ito/update/firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
fumito-ito authored May 14, 2022
2 parents adec616 + a417c63 commit 3b5782b
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseRemoteConfigBinary.json"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseProtobufBinary.json"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseRemoteConfigBinary.json" ~> 9.0.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseProtobufBinary.json" ~> 9.0.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" ~> 9.0.0
7 changes: 3 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -20,16 +20,15 @@ let package = Package(
],
dependencies: [
.package(
name: "Firebase",
url: "https://github.com/firebase/firebase-ios-sdk.git",
.upToNextMajor(from: "8.12.1")
.upToNextMajor(from: "9.0.0")
),
],
targets: [
.target(
name: "SwiftyRemoteConfig",
dependencies: [
.product(name: "FirebaseRemoteConfig", package: "Firebase")
.product(name: "FirebaseRemoteConfig", package: "firebase-ios-sdk")
],
path: "Sources"
),
Expand Down
99 changes: 94 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,96 @@

SwiftyRemoteConfig makes Firebase Remote Config enjoyable to use by combining expressive Swifty API with the benefits fo static typing. This library is strongly inspired by [SwiftyUserDefaults](https://github.com/sunshinejr/SwiftyUserDefaults).

## Features
## HEADS UP ! You need workaround to use with Xcode 13.3 or later

Because of [Xcode compiler bug](https://github.com/apple/swift/issues/58084), you need workaround to use this library with Xcode 13.3 or later.
Followings are recommended steps for workaround.

1. Create `SwiftyRemoteConfig+Workaround.swift` file in module whitch is using `SwiftyRemoteConfig`.
1. Copy the codes below into `SwiftyRemoteConfig+Workaround.swift`. This is pretty much a copy from the `BuiltIns.swift` file in the Sources folder: https://raw.githubusercontent.com/fumito-ito/SwiftyRemoteConfig/master/Sources/SwiftyRemoteConfig/BuiltIns.swift

```swift
import Foundation
import SwiftyRemoteConfig

extension RemoteConfigSerializable {
public static var _remoteConfigArray: RemoteConfigArrayBridge<[T]> { RemoteConfigArrayBridge() }
}

extension Date: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigObjectBridge<Date> { RemoteConfigObjectBridge() }
}

extension String: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigStringBridge { RemoteConfigStringBridge() }
}

extension Int: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigIntBridge { RemoteConfigIntBridge() }
}

extension Double: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigDoubleBridge { return RemoteConfigDoubleBridge() }
}

extension Bool: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigBoolBridge { RemoteConfigBoolBridge() }
}

extension Data: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigDataBridge { RemoteConfigDataBridge() }
}

extension URL: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigUrlBridge { RemoteConfigUrlBridge() }
public static var _remoteConfigArray: RemoteConfigCodableBridge<[URL]> { RemoteConfigCodableBridge() }
}

extension RemoteConfigSerializable where Self: Codable {
public static var _remoteConfig: RemoteConfigCodableBridge<Self> { RemoteConfigCodableBridge() }
public static var _remoteConfigArray: RemoteConfigCodableBridge<[Self]> { RemoteConfigCodableBridge() }
}

extension RemoteConfigSerializable where Self: RawRepresentable {
public static var _remoteConfig: RemoteConfigRawRepresentableBridge<Self> { RemoteConfigRawRepresentableBridge() }
public static var _remoteConfigArray: RemoteConfigRawRepresentableArrayBridge<[Self]> { RemoteConfigRawRepresentableArrayBridge() }
}

extension RemoteConfigSerializable where Self: NSCoding {
public static var _remoteConfig: RemoteConfigKeyedArchiverBridge<Self> { RemoteConfigKeyedArchiverBridge() }
public static var _remoteConfigArray: RemoteConfigKeyedArchiverArrayBridge<[Self]> { RemoteConfigKeyedArchiverArrayBridge() }
}

extension Dictionary: RemoteConfigSerializable where Key == String {
public typealias T = [Key: Value]
public typealias Bridge = RemoteConfigObjectBridge<T>
public typealias ArrayBridge = RemoteConfigArrayBridge<[T]>

public static var _remoteConfig: Bridge { Bridge() }
public static var _remoteConfigArray: ArrayBridge { ArrayBridge() }
}

extension Array: RemoteConfigSerializable where Element: RemoteConfigSerializable {
public typealias T = [Element.T]
public typealias Bridge = Element.ArrayBridge
public typealias ArrayBridge = RemoteConfigObjectBridge<[T]>

public static var _remoteConfig: Bridge { Element._remoteConfigArray }
public static var _remoteConfigArray: ArrayBridge {
fatalError("Multidimensional arrays are not supported yet")
}
}

extension Optional: RemoteConfigSerializable where Wrapped: RemoteConfigSerializable {
public typealias Bridge = RemoteConfigOptionalBridge<Wrapped.Bridge>
public typealias ArrayBridge = RemoteConfigOptionalBridge<Wrapped.ArrayBridge>

public static var _remoteConfig: Bridge { RemoteConfigOptionalBridge(bridge: Wrapped._remoteConfig) }
public static var _remoteConfigArray: ArrayBridge { RemoteConfigOptionalBridge(bridge: Wrapped._remoteConfigArray) }
}
```

## Features

There is only one step to start using SwiftyRemoteConfig.

Expand Down Expand Up @@ -334,7 +423,7 @@ final class ViewModel: ObservableObject {

### Frameworks

- **Firebase iOS SDK** >= 8.0.0
- **Firebase iOS SDK** >= 9.0.0

## Installation

Expand All @@ -343,7 +432,7 @@ final class ViewModel: ObservableObject {
If you're using Cocoapods, just add this line to your `Podfile`:

```ruby
pod 'SwiftyRemoteConfig`, `~> 0.2.1`
pod 'SwiftyRemoteConfig`, `~> 0.3.0`
```
Install by running this command in your terminal:
Expand All @@ -363,7 +452,7 @@ import SwiftyRemoteConfig
Just add your Cartfile
```
github "fumito-ito/SwiftyRemoteConfig" ~> 0.2.1
github "fumito-ito/SwiftyRemoteConfig" ~> 0.3.0
```
### Swift Package Manager
Expand All @@ -375,7 +464,7 @@ let package = Package(
name: "MyPackage",
products: [...],
dependencies: [
.package(url: "https://github.com/fumito-ito/SwiftyRemoteConfig.git", .upToNextMajor(from: "0.2.1"))
.package(url: "https://github.com/fumito-ito/SwiftyRemoteConfig.git", .upToNextMajor(from: "0.3.0"))
]
)
```
Expand Down
10 changes: 10 additions & 0 deletions Sources/SwiftyRemoteConfig/RemoteConfigBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public struct RemoteConfigCodableBridge<T: Codable>: RemoteConfigBridge {
public func deserialize(_ object: RemoteConfigValue) -> T? {
return try? JSONDecoder().decode(T.self, from: object.dataValue)
}

public init() {}
}

public struct RemoteConfigKeyedArchiverBridge<T: NSCoding>: RemoteConfigBridge {
Expand All @@ -172,6 +174,8 @@ public struct RemoteConfigKeyedArchiverBridge<T: NSCoding>: RemoteConfigBridge {

return object
}

public init() {}
}

public struct RemoteConfigKeyedArchiverArrayBridge<T: Collection>: RemoteConfigBridge where T.Element: NSCoding {
Expand All @@ -192,6 +196,8 @@ public struct RemoteConfigKeyedArchiverArrayBridge<T: Collection>: RemoteConfigB
try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [T.Element.self], from: $0) as? T.Element
}) as? T
}

public init() {}
}

public struct RemoteConfigRawRepresentableBridge<T: RawRepresentable>: RemoteConfigBridge {
Expand All @@ -210,6 +216,8 @@ public struct RemoteConfigRawRepresentableBridge<T: RawRepresentable>: RemoteCon

return nil
}

public init() {}
}

public struct RemoteConfigRawRepresentableArrayBridge<T: Collection>: RemoteConfigBridge where T.Element: RawRepresentable {
Expand All @@ -224,6 +232,8 @@ public struct RemoteConfigRawRepresentableArrayBridge<T: Collection>: RemoteConf

return rawValues.compactMap({ T.Element(rawValue: $0) }) as? T
}

public init() {}
}

public struct RemoteConfigOptionalBridge<Bridge: RemoteConfigBridge>: RemoteConfigBridge {
Expand Down
6 changes: 3 additions & 3 deletions SwiftyRemoteConfig.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "SwiftyRemoteConfig"
spec.version = "0.2.1"
spec.version = "0.3.0"
spec.summary = "Modern Swift API for FirebaseRemoteConfig"

spec.description = <<-DESC
Expand All @@ -19,9 +19,9 @@ Pod::Spec.new do |spec|
spec.source = { :git => "https://github.com/fumito-ito/SwiftyRemoteConfig.git", :tag => "#{spec.version}" }
spec.source_files = "Sources", "Sources/**/*.swift"
spec.requires_arc = true
spec.swift_version = "5.0", "5.1", "5.2"
spec.swift_versions = "5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6"

spec.static_framework = true
spec.dependency "FirebaseRemoteConfig", "~> 8.12.1"
spec.dependency "FirebaseRemoteConfig", "~> 9.0.0"

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// SwiftyRemoteConfig+Workaround.swift
//
//
// Created by Fumito Ito on 2022/05/14.
//

import Foundation
import SwiftyRemoteConfig

extension RemoteConfigSerializable {
public static var _remoteConfigArray: RemoteConfigArrayBridge<[T]> { RemoteConfigArrayBridge() }
}

extension Date: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigObjectBridge<Date> { RemoteConfigObjectBridge() }
}

extension String: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigStringBridge { RemoteConfigStringBridge() }
}

extension Int: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigIntBridge { RemoteConfigIntBridge() }
}

extension Double: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigDoubleBridge { return RemoteConfigDoubleBridge() }
}

extension Bool: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigBoolBridge { RemoteConfigBoolBridge() }
}

extension Data: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigDataBridge { RemoteConfigDataBridge() }
}

extension URL: RemoteConfigSerializable {
public static var _remoteConfig: RemoteConfigUrlBridge { RemoteConfigUrlBridge() }
public static var _remoteConfigArray: RemoteConfigCodableBridge<[URL]> { RemoteConfigCodableBridge() }
}

extension RemoteConfigSerializable where Self: Codable {
public static var _remoteConfig: RemoteConfigCodableBridge<Self> { RemoteConfigCodableBridge() }
public static var _remoteConfigArray: RemoteConfigCodableBridge<[Self]> { RemoteConfigCodableBridge() }
}

extension RemoteConfigSerializable where Self: RawRepresentable {
public static var _remoteConfig: RemoteConfigRawRepresentableBridge<Self> { RemoteConfigRawRepresentableBridge() }
public static var _remoteConfigArray: RemoteConfigRawRepresentableArrayBridge<[Self]> { RemoteConfigRawRepresentableArrayBridge() }
}

extension RemoteConfigSerializable where Self: NSCoding {
public static var _remoteConfig: RemoteConfigKeyedArchiverBridge<Self> { RemoteConfigKeyedArchiverBridge() }
public static var _remoteConfigArray: RemoteConfigKeyedArchiverArrayBridge<[Self]> { RemoteConfigKeyedArchiverArrayBridge() }
}

extension Dictionary: RemoteConfigSerializable where Key == String {
public typealias T = [Key: Value]
public typealias Bridge = RemoteConfigObjectBridge<T>
public typealias ArrayBridge = RemoteConfigArrayBridge<[T]>

public static var _remoteConfig: Bridge { Bridge() }
public static var _remoteConfigArray: ArrayBridge { ArrayBridge() }
}

extension Array: RemoteConfigSerializable where Element: RemoteConfigSerializable {
public typealias T = [Element.T]
public typealias Bridge = Element.ArrayBridge
public typealias ArrayBridge = RemoteConfigObjectBridge<[T]>

public static var _remoteConfig: Bridge { Element._remoteConfigArray }
public static var _remoteConfigArray: ArrayBridge {
fatalError("Multidimensional arrays are not supported yet")
}
}

extension Optional: RemoteConfigSerializable where Wrapped: RemoteConfigSerializable {
public typealias Bridge = RemoteConfigOptionalBridge<Wrapped.Bridge>
public typealias ArrayBridge = RemoteConfigOptionalBridge<Wrapped.ArrayBridge>

public static var _remoteConfig: Bridge { RemoteConfigOptionalBridge(bridge: Wrapped._remoteConfig) }
public static var _remoteConfigArray: ArrayBridge { RemoteConfigOptionalBridge(bridge: Wrapped._remoteConfigArray) }
}

0 comments on commit 3b5782b

Please sign in to comment.