7 Commits
0.0.5 ... 0.0.7

Author SHA1 Message Date
Oleksii Dykan
3cae6e90d9 Bump version number 2018-02-20 23:13:02 +01:00
Oleksii Dykan
222b080693 Merge pull request #24 from alickbass/update-encoder
Update Encoder
2018-02-20 23:11:31 +01:00
Oleksii Dykan
5b8627dbbe If the value pushed a container before throwing, pop it back off to restore state 2018-02-20 23:00:29 +01:00
Oleksii Dykan
1384814716 Bump version number 2018-02-11 11:44:17 +01:00
Oleksii Dykan
b0e86866a0 Merge pull request #21 from alickbass/fix-decimal-encoding
Fix handling decimal value
2018-02-11 11:41:33 +01:00
Oleksii Dykan
0c60f70d91 Fix handling decimal value 2018-02-11 11:29:42 +01:00
Oleksii Dykan
df9dfe1dda Fix cocoapods link 2018-01-30 10:56:48 +01:00
5 changed files with 22 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CodableFirebase"
s.version = "0.0.5"
s.version = "0.0.7"
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

@@ -383,6 +383,8 @@ extension _FirebaseEncoder {
return try self.box((value as! Data))
} else if T.self == URL.self || T.self == NSURL.self {
return self.box((value as! URL).absoluteString)
} else if T.self == Decimal.self || T.self == NSDecimalNumber.self {
return (value as! NSDecimalNumber)
} else if options.skipFirestoreTypes && (value is FirestoreEncodable) {
guard let value = value as? NSObject else {
throw DocumentReferenceError.typeIsNotNSObject
@@ -391,11 +393,20 @@ extension _FirebaseEncoder {
}
// The value should request a container from the _FirebaseEncoder.
let depth = storage.count
try value.encode(to: self)
let depth = self.storage.count
do {
try value.encode(to: self)
} catch {
// If the value pushed a container before throwing, pop it back off to restore state.
if self.storage.count > depth {
let _ = self.storage.popContainer()
}
throw error
}
// The top container should be a new container.
guard storage.count > depth else {
guard self.storage.count > depth else {
return nil
}

View File

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

View File

@@ -109,6 +109,11 @@ class TestCodableFirestore: XCTestCase {
_testRoundTrip(of: TopLevelWrapper(date), expected: ["value": date])
}
func testDecimalValue() {
let value = Decimal(2)
_testRoundTrip(of: TopLevelWrapper(value), expected: ["value": value])
}
// MARK: - GeoPoint & Document Reference
func testEncodingGeoPoint() {
let point = GeoPoint(latitude: 2, longitude: 2)

View File

@@ -1,7 +1,7 @@
# CodableFirebase
Use [Codable](https://developer.apple.com/documentation/swift/codable) with [Firebase](https://firebase.google.com)
[![CocoaPods](https://img.shields.io/cocoapods/p/CodableFirebase.svg)]()
[![CocoaPods](https://img.shields.io/cocoapods/p/CodableFirebase.svg)](https://github.com/alickbass/CodableFirebase)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Build Status](https://travis-ci.org/alickbass/CodableFirebase.svg?branch=master)](https://travis-ci.org/alickbass/CodableFirebase)