13 Commits

Author SHA1 Message Date
Oleksii Dykan
1319fdb902 0.2.1 release 2018-09-25 23:09:28 +01:00
Oleksii Dykan
6d6ad92bee Force to use libraries when using cocoapods 2018-09-25 23:07:06 +01:00
Oleksii Dykan
49299dd857 Merge pull request #54 from serjooo/master
Updated to Swift 4.2
2018-09-20 10:20:54 +01:00
Serj
df13646d4d Updated travis.yml to latest xcode version
Updated travis.yml to latest xcode version
2018-09-20 11:25:55 +03:00
Serj
b83a25bf60 Updated to Swift 4.2
Changed the Swift version in build settings. No source code changes was needed.
2018-09-20 10:15:19 +03:00
Oleksii Dykan
4b967b2c91 Merge pull request #45 from natan/readme-update-cloudfirestore
README.md updates: update product name, small consistency tweaks
2018-05-31 22:03:10 +01:00
nathan spindel
c999e5375d README.md updates: update product name, small consistency tweaks 2018-05-31 13:08:12 -07:00
Oleksii Dykan
957809a715 0.2.0 release 2018-05-19 22:29:52 +02:00
Oleksii Dykan
f445059fdb 0.1.0 release 2018-05-19 22:22:49 +02:00
Oleksii Dykan
25867e12c9 Merge pull request #43 from alickbass/support-firtimestamp
Add support for FirTimestamp
2018-05-19 21:19:19 +01:00
Oleksii Dykan
0d4a779a85 Update README 2018-05-19 20:01:28 +02:00
Oleksii Dykan
c17c0603b2 Add support for FirTimestamp 2018-05-19 19:50:58 +02:00
Marcos Griselli
f1d465b936 0.0.12 release 2018-05-14 10:45:12 -03:00
10 changed files with 99 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.3
osx_image: xcode10.0
env:
- ACTION=test PLATFORM=Mac DESTINATION='platform=OS X'

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CodableFirebase"
s.version = "0.0.11"
s.version = "0.2.1"
s.summary = "Use Codable with Firebase"
s.description = "This library helps you use your custom models that conform to Codable protocol with Firebase Realtime Database and Firestore"
s.homepage = "https://github.com/alickbass/CodableFirebase"

View File

@@ -177,6 +177,7 @@
};
CE7DD36F1F9CFA81000225C5 = {
CreatedOnToolsVersion = 9.0.1;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
@@ -389,7 +390,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator macosx";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
@@ -418,7 +419,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator macosx";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
@@ -441,7 +442,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos watchos macosx appletvsimulator iphonesimulator watchsimulator";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
@@ -464,7 +465,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos watchos macosx appletvsimulator iphonesimulator watchsimulator";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;

View File

@@ -20,6 +20,11 @@ public protocol GeoPointType: FirestoreDecodable, FirestoreEncodable {
init(latitude: Double, longitude: Double)
}
public protocol TimestampType: FirestoreDecodable, FirestoreEncodable {
init(date: Date)
func dateValue() -> Date
}
open class FirestoreDecoder {
public init() {}
@@ -76,3 +81,15 @@ extension FirestoreEncodable {
throw DocumentReferenceError.typeIsNotSupported
}
}
extension TimestampType {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.init(date: try container.decode(Date.self))
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.dateValue())
}
}

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.0.11</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.11</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>

View File

@@ -95,6 +95,11 @@ class TestCodableFirebase: XCTestCase {
expectedValue: expected,
dateEncodingStrategy: .secondsSince1970,
dateDecodingStrategy: .secondsSince1970)
_testRoundTrip(of: TopLevelWrapper(FirTimestamp(date: Date(timeIntervalSince1970: seconds))),
expectedValue: expected,
dateEncodingStrategy: .secondsSince1970,
dateDecodingStrategy: .secondsSince1970)
_testRoundTrip(of: OptionalTopLevelWrapper(Date(timeIntervalSince1970: seconds)),
expectedValue: expected,
@@ -500,6 +505,22 @@ fileprivate struct Timestamp : Codable, Equatable {
}
}
fileprivate struct FirTimestamp : TimestampType, Equatable {
let date: Date
init(date: Date) {
self.date = date
}
func dateValue() -> Date {
return date
}
static func == (_ lhs: FirTimestamp, _ rhs: FirTimestamp) -> Bool {
return lhs.date == rhs.date
}
}
/// A simple referential counter type that encodes as a single Int value.
fileprivate final class Counter : Codable, Equatable {
var count: Int = 0

View File

@@ -128,7 +128,14 @@ class TestCodableFirestore: XCTestCase {
XCTAssertEqual((try? FirestoreEncoder().encode(val)) as NSDictionary?, ["value": val.value])
XCTAssertEqual(try? FirestoreDecoder().decode(TopLevelWrapper<DocumentReference>.self, from: ["value": val.value]), val)
}
func testEncodingTimestamp() {
let timestamp = Timestamp(date: Date())
let wrapper = TopLevelWrapper(timestamp)
XCTAssertEqual((try? FirestoreEncoder().encode(wrapper)) as NSDictionary?, ["value": timestamp])
XCTAssertEqual(try? FirestoreDecoder().decode(TopLevelWrapper<Timestamp>.self, from: ["value": timestamp]), wrapper)
}
private func _testEncodeFailure<T : Encodable>(of value: T) {
do {
let _ = try FirestoreEncoder().encode(value)
@@ -195,10 +202,29 @@ fileprivate class GeoPoint: NSObject, GeoPointType {
self.longitude = longitude
}
static func == (lhs: Point, rhs: Point) -> Bool {
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
override func isEqual(_ object: Any?) -> Bool {
guard let other = object.flatMap({ $0 as? GeoPoint }) else { return false }
return latitude == other.latitude && longitude == other.longitude
}
}
// MARK: - ReferenceType
fileprivate class DocumentReference: NSObject, DocumentReferenceType {}
// MARK: - Timestamp
fileprivate class Timestamp: NSObject, TimestampType {
let date: Date
required init(date: Date) {
self.date = date
}
func dateValue() -> Date {
return date
}
override func isEqual(_ object: Any?) -> Bool {
guard let other = object.flatMap({ $0 as? Timestamp }) else { return false }
return date == other.date
}
}

View File

@@ -20,13 +20,13 @@ struct Model: Codable {
let numberExample: Double
let dateExample: Date
let arrayExample: [String]
let nullExample: Int?
let optionalExample: Int?
let objectExample: [String: String]
let myEnum: MyEnum
let myEnumExample: MyEnum
}
```
### Firebase Database usage
### Firebase Realtime Database usage
This is how you would use the library with [Firebase Realtime Database](https://firebase.google.com/products/realtime-database/):
@@ -43,7 +43,7 @@ Database.database().reference().child("model").setValue(data)
And here is how you would read the same value from [Firebase Realtime Database](https://firebase.google.com/products/realtime-database/):
```swift
Database.database().reference().child("model").observeSingleEvent(of: .value, with: { (snapshot) in
Database.database().reference().child("model").observeSingleEvent(of: .value, with: { snapshot in
guard let value = snapshot.value else { return }
do {
let model = try FirebaseDecoder().decode(Model.self, from: value)
@@ -54,9 +54,9 @@ Database.database().reference().child("model").observeSingleEvent(of: .value, wi
})
```
### Firestore usage
### Firebase Cloud Firestore usage
And this is how you would encode it with [Firebase Firestore](https://firebase.google.com/products/firestore/):
This is how you would encode a model with [Firebase Cloud Firestore](https://firebase.google.com/products/firestore/):
```swift
import Firebase
@@ -64,19 +64,19 @@ import CodableFirebase
let model: Model // here you will create an instance of Model
let docData = try! FirestoreEncoder().encode(model)
Firestore.firestore().collection("data").document("one").setData(docData) { err in
if let err = err {
print("Error writing document: \(err)")
Firestore.firestore().collection("data").document("one").setData(docData) { error in
if let error = error {
print("Error writing document: \(error)")
} else {
print("Document successfully written!")
}
}
```
And this is how you would decode the same model with [Firebase Firestore](https://firebase.google.com/products/firestore/):
And this is how you would decode the same model with [Firebase Cloud Firestore](https://firebase.google.com/products/firestore/):
```swift
Firestore.firestore().collection("data").document("one").getDocument { (document, error) in
Firestore.firestore().collection("data").document("one").getDocument { document, error in
if let document = document {
let model = try! FirestoreDecoder().decode(Model.self, from: document.data())
print("Model: \(model)")
@@ -86,14 +86,15 @@ Firestore.firestore().collection("data").document("one").getDocument { (document
}
```
### How to use `GeoPoint`, `DocumentRefence`, `FieldValue` in Firestore
#### How to use `GeoPoint`, `DocumentRefence`, `FieldValue`, `Timestamp` in Cloud Firestore
In order to use these 2 types with `Firestore`, you need to add the following code somewhere in your app:
In order to use these types with Cloud Firestore, you need to add the following code somewhere in your app:
```swift
extension DocumentReference: DocumentReferenceType {}
extension GeoPoint: GeoPointType {}
extension FieldValue: FieldValueType {}
extension Timestamp: TimestampType {}
```
and now they become `Codable` and can be used properly with `FirestoreEncoder` and `FirestoreDecoder`.
@@ -111,7 +112,7 @@ platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'CodableFirebase'
pod 'CodableFirebase'
end
```

View File

@@ -18,7 +18,10 @@ platform :ios do
end
def release(type)
pod_lib_lint
pod_lib_lint(
allow_warnings: true,
use_libraries: true,
)
podspec_name = "CodableFirebase.podspec"
version = version_bump_podspec(path: podspec_name,
bump_type: type)
@@ -29,6 +32,9 @@ platform :ios do
message: "#{version} release")
add_git_tag(tag: "#{version}")
push_to_git_remote
pod_push
pod_push(
allow_warnings: true,
use_libraries: true,
)
end
end