-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codable firestore #838
Codable firestore #838
Changes from 20 commits
3598b86
959cc57
ad832a1
24daa10
6fc2dd4
b5d72b0
c719b85
448bbbf
557883e
86bbf4b
cb7e0a8
6303624
f20e338
9f13acf
a423896
dcc4b4a
493a157
c9b35c7
05e20fd
735331d
889f29a
4fed07f
ccdd0fc
93f7430
abe43e4
073901a
a62364d
f19ea99
3ea3eba
d23c201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# Be sure to run `pod lib lint FirebaseFirestoreSwift.podspec' to ensure this is a | ||
# valid spec before submitting. | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'FirebaseFirestoreSwift' | ||
s.version = '0.10.1' | ||
s.summary = 'Google Cloud Firestore for iOS Swift Extensions' | ||
|
||
s.description = <<-DESC | ||
Google Cloud Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. | ||
DESC | ||
|
||
s.homepage = 'https://developers.google.com/' | ||
s.license = { :type => 'Apache', :file => 'LICENSE' } | ||
s.authors = 'Google, Inc.' | ||
|
||
s.source = { | ||
:git => 'https://github.com/Firebase/firebase-ios-sdk.git', | ||
:tag => s.version.to_s | ||
} | ||
|
||
s.swift_version = '4.0' | ||
s.ios.deployment_target = '8.0' | ||
|
||
s.cocoapods_version = '>= 1.4.0' | ||
s.static_framework = true | ||
s.prefix_header_file = false | ||
|
||
s.requires_arc = true | ||
s.source_files = [ | ||
'Firestore/Swift/Source/**/*.swift', | ||
] | ||
|
||
s.dependency 'FirebaseFirestore', "= #{s.version}" | ||
end |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All files need a copyright notice to be in this repo. You can copy from the top of any existing file and adjust the date or use this: /*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just re-read our internal style guide and realized that these files should really be Class+Protocol.swift. In this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// CodableDocumentReference.swift | ||
// FirebaseFirestoreSwift | ||
// | ||
// Created by Oleksii on 22/02/2018. | ||
// | ||
|
||
import FirebaseFirestore | ||
|
||
enum FirestoreDecodingError: Error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These don't have much to do with DocumentReference. Perhaps put these in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
case decodingIsNotSupported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Google's coding style requires two space indents. Rather than fix this by hand please wait for PR #847 to land and run that here to fix this. |
||
} | ||
|
||
enum FirestoreEncodingError: Error { | ||
case encodingIsNotSupported | ||
} | ||
|
||
/** | ||
* A protocol describing the encodable properties of a DocumentReference. | ||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the DocumentReference class was | ||
* extended directly to conform to Codable, the methods implementing the protcol would be need to be | ||
* marked required but that can't be done in an extension. Declaring the extension on the protocol | ||
* sidesteps this issue. | ||
*/ | ||
fileprivate protocol CodableDocumentReference: Codable {} | ||
|
||
extension CodableDocumentReference { | ||
public init(from decoder: Decoder) throws { | ||
throw FirestoreDecodingError.decodingIsNotSupported | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
throw FirestoreEncodingError.encodingIsNotSupported | ||
} | ||
} | ||
|
||
extension DocumentReference: CodableDocumentReference {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// CodableFieldValue.swift | ||
// FirebaseFirestoreSwift | ||
// | ||
// Created by Oleksii on 22/02/2018. | ||
// | ||
|
||
import FirebaseFirestore | ||
|
||
/** | ||
* A protocol describing the encodable properties of a FirebaseFirestore. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the encodable properties of a FieldValue, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the FirebaseFirestore class was | ||
* extended directly to conform to Codable, the methods implementing the protcol would be need to be | ||
* marked required but that can't be done in an extension. Declaring the extension on the protocol | ||
* sidesteps this issue. | ||
*/ | ||
fileprivate protocol CodableFieldValue: Encodable {} | ||
|
||
extension CodableFieldValue { | ||
public func encode(to encoder: Encoder) throws { | ||
throw FirestoreEncodingError.encodingIsNotSupported | ||
} | ||
} | ||
|
||
extension FieldValue: CodableFieldValue {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import FirebaseFirestore | ||
|
||
/** | ||
* A protocol describing the encodable properties of a GeoPoint. | ||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the GeoPoint class was | ||
* extended directly to conform to Codable, the methods implementing the protcol would be need to be | ||
* marked required but that can't be done in an extension. Declaring the extension on the protocol | ||
* sidesteps this issue. | ||
*/ | ||
fileprivate protocol CodableGeoPoint: Codable { | ||
var latitude: Double { get } | ||
var longitude: Double { get } | ||
|
||
init(latitude: Double, longitude: Double) | ||
} | ||
|
||
/** The keys in a GeoPoint. Must match the properties of CodableGeoPoint. */ | ||
fileprivate enum GeoPointKeys: String, CodingKey { | ||
case latitude | ||
case longitude | ||
} | ||
|
||
/** | ||
* An extension of GeoPoint that implements the behavior of the Codable protocol. | ||
* | ||
* Note: this is implemented manually here because the Swift compiler can't synthesize these methods | ||
* when declaring an extension to conform to Codable. | ||
*/ | ||
extension CodableGeoPoint { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: GeoPointKeys.self) | ||
let latitude = try container.decode(Double.self, forKey: .latitude) | ||
let longitude = try container.decode(Double.self, forKey: .longitude) | ||
self.init(latitude: latitude, longitude: longitude) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: GeoPointKeys.self) | ||
try container.encode(latitude, forKey: .latitude) | ||
try container.encode(longitude, forKey: .longitude) | ||
} | ||
} | ||
|
||
/** Extends GeoPoint to conform to Codable. */ | ||
extension GeoPoint: CodableGeoPoint {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base state from which you branched was broken. I've since fixed this, but unfortunately these diffs remain. For all the
.xcscheme
files, make sure your upstream branch is up-to-date and then git checkout the master version of these files and commit them. After pushing you shouldn't see any additions to project files.