Skip to content

Commit 90fcfa8

Browse files
committed
Support swift4.1
1 parent 882b880 commit 90fcfa8

File tree

12 files changed

+65
-49
lines changed

12 files changed

+65
-49
lines changed

Pring.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
isa = PBXProject;
403403
attributes = {
404404
LastSwiftUpdateCheck = 0910;
405-
LastUpgradeCheck = 0910;
405+
LastUpgradeCheck = 0930;
406406
ORGANIZATIONNAME = "Stamp Inc";
407407
TargetAttributes = {
408408
12AF82F31F8CAEDE00561159 = {
@@ -772,13 +772,15 @@
772772
CLANG_WARN_BOOL_CONVERSION = YES;
773773
CLANG_WARN_COMMA = YES;
774774
CLANG_WARN_CONSTANT_CONVERSION = YES;
775+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
775776
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
776777
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
777778
CLANG_WARN_EMPTY_BODY = YES;
778779
CLANG_WARN_ENUM_CONVERSION = YES;
779780
CLANG_WARN_INFINITE_RECURSION = YES;
780781
CLANG_WARN_INT_CONVERSION = YES;
781782
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
783+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
782784
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
783785
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
784786
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -832,13 +834,15 @@
832834
CLANG_WARN_BOOL_CONVERSION = YES;
833835
CLANG_WARN_COMMA = YES;
834836
CLANG_WARN_CONSTANT_CONVERSION = YES;
837+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
835838
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
836839
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
837840
CLANG_WARN_EMPTY_BODY = YES;
838841
CLANG_WARN_ENUM_CONVERSION = YES;
839842
CLANG_WARN_INFINITE_RECURSION = YES;
840843
CLANG_WARN_INT_CONVERSION = YES;
841844
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
845+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
842846
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
843847
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
844848
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Pring/AnySubCollection.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,14 @@ public protocol AnySubCollection: class, StorageLinkable, Batchable {
2727
func setParent(_ object: Object, forKey key: String)
2828
}
2929

30-
extension AnySubCollection {
30+
public extension AnySubCollection {
3131

3232
public func setParent(_ object: Object, forKey key: String) {
3333
self.parent = object
3434
self.key = key
3535
}
3636
}
3737

38-
extension AnySubCollection where Self: Collection, Self.Element: Document {
39-
40-
public func shouldUploadFiles(_ id: String) -> Bool {
41-
for (_, document) in self.enumerated() {
42-
if document.shouldUploadFiles(id) {
43-
return true
44-
}
45-
}
46-
return false
47-
}
48-
49-
public func saveFiles(_ id: String, container: UploadContainer? = nil, block: ((Error?) -> Void)?) -> [String: StorageUploadTask] {
50-
let uploadContainer: UploadContainer = container ?? UploadContainer()
51-
self.forEach { document in
52-
document.saveFiles(id, container: uploadContainer, block: nil)
53-
}
54-
return uploadContainer.tasks
55-
}
56-
57-
public func deleteFiles(container: DeleteContainer? = nil, block: ((Error?) -> Void)?) {
58-
let deleteContainer: DeleteContainer = container ?? DeleteContainer()
59-
self.forEach { document in
60-
document.deleteFiles(container: deleteContainer, block: nil)
61-
}
62-
}
63-
}
64-
6538
public extension AnySubCollection where Self: Collection, Self.Element: Document {
6639

6740
public var query: DataSource<Self.Element>.Query {

Pring/DataSource.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public final class DataSource<T: Document>: ExpressibleByArrayLiteral {
238238
let id: String = change.document.documentID
239239
switch change.type {
240240
case .added:
241-
guard !self.documents.flatMap({return $0.id}).contains(id) else {
241+
guard !self.documents.compactMap({return $0.id}).contains(id) else {
242242
return
243243
}
244244
group.enter()
@@ -275,7 +275,7 @@ public final class DataSource<T: Document>: ExpressibleByArrayLiteral {
275275
}
276276
})
277277
case .modified:
278-
guard self.documents.flatMap({return $0.id}).contains(id) else {
278+
guard self.documents.compactMap({return $0.id}).contains(id) else {
279279
return
280280
}
281281
group.enter()
@@ -318,7 +318,7 @@ public final class DataSource<T: Document>: ExpressibleByArrayLiteral {
318318
}
319319
})
320320
case .removed:
321-
guard self.documents.flatMap({return $0.id}).contains(id) else {
321+
guard self.documents.compactMap({return $0.id}).contains(id) else {
322322
return
323323
}
324324
group.enter()
@@ -490,7 +490,7 @@ extension DataSource: Collection {
490490
extension Array where Element: Document {
491491

492492
public var keys: [String] {
493-
return self.flatMap { return $0.id }
493+
return self.compactMap { return $0.id }
494494
}
495495

496496
public func index(of key: String) -> Int? {

Pring/DataType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public enum DataType {
262262
}
263263
} else if subjectType == [File].self || subjectType == [File]?.self {
264264
if let value: [[AnyHashable: String]] = data[key] as? [[AnyHashable: String]] {
265-
let files: [File] = value.flatMap { return File(property: $0) }
265+
let files: [File] = value.compactMap { return File(property: $0) }
266266
self = .files(key, value, files)
267267
return
268268
}

Pring/Document.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public protocol Document: NSObjectProtocol, Hashable, StorageLinkable, Batchable
7171
public extension Document where Self: Object {
7272

7373
public func shouldUploadFiles(_ id: String) -> Bool {
74-
if id == self.uploadID {
74+
if id == self.batchID {
7575
return false
7676
}
77-
self.uploadID = id
77+
self.batchID = id
7878
let mirror = Mirror(reflecting: self)
7979
for (_, child) in mirror.children.enumerated() {
8080
if let key: String = child.label {
@@ -112,10 +112,10 @@ public extension Document where Self: Object {
112112

113113
var uploadContainer: UploadContainer = container ?? UploadContainer()
114114

115-
if id == self.uploadID {
115+
if id == self.batchID {
116116
return uploadContainer.tasks
117117
}
118-
self.uploadID = id
118+
self.batchID = id
119119

120120
for (_, child) in Mirror(reflecting: self).children.enumerated() {
121121

@@ -182,10 +182,15 @@ public extension Document where Self: Object {
182182
return uploadContainer.tasks
183183
}
184184

185-
public func deleteFiles(container: DeleteContainer?, block: ((Error?) -> Void)?) {
185+
public func deleteFiles(_ id: String, container: DeleteContainer?, block: ((Error?) -> Void)?) {
186186

187187
var deleteContainer: DeleteContainer = container ?? DeleteContainer()
188188

189+
if id == self.batchID {
190+
return
191+
}
192+
self.batchID = id
193+
189194
for (_, child) in Mirror(reflecting: self).children.enumerated() {
190195
guard let key: String = child.label else { break }
191196
if self.ignore.contains(key) { break }

Pring/Object.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ open class Object: NSObject, Document {
7070

7171
public var batchID: String?
7272

73-
public var uploadID: String?
74-
7573
private var _hash: Int?
7674

7775
/// isObserving is a flag that indicates that Document is concerned with my Field.
@@ -345,7 +343,7 @@ open class Object: NSObject, Document {
345343
return
346344
}
347345

348-
let keys: [String] = Mirror(reflecting: self).children.flatMap({ return $0.label })
346+
let keys: [String] = Mirror(reflecting: self).children.compactMap({ return $0.label })
349347
if keys.contains(keyPath) {
350348

351349
if let value: Any = object.value(forKey: keyPath) as Any? {
@@ -612,7 +610,7 @@ open class Object: NSObject, Document {
612610

613611
public func delete(_ batch: WriteBatch? = nil, block: ((Error?) -> Void)? = nil) {
614612
let batch: WriteBatch = batch ?? Firestore.firestore().batch()
615-
self.deleteFiles(container: nil) { (error) in
613+
self.deleteFiles(UUID().uuidString, container: nil) { (error) in
616614
self.pack(.delete, batch: batch).commit { (error) in
617615
if let error = error {
618616
block?(error)

Pring/Reference.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import FirebaseStorage
1111

1212
public protocol HasParent {
1313

14-
weak var parent: Object? { get }
14+
var parent: Object? { get }
1515

1616
var key: String? { get }
1717

@@ -46,9 +46,9 @@ extension AnyReference where Self: HasDocument {
4646
return uploadContainer.tasks
4747
}
4848

49-
public func deleteFiles(container: DeleteContainer?, block: ((Error?) -> Void)?) {
49+
public func deleteFiles(_ id: String, container: DeleteContainer?, block: ((Error?) -> Void)?) {
5050
let deleteContainer: DeleteContainer = container ?? DeleteContainer()
51-
self.deleteFiles(container: deleteContainer, block: nil)
51+
self.deleteFiles(id, container: deleteContainer, block: nil)
5252
}
5353
}
5454

Pring/ReferenceCollection.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,9 @@ public class ReferenceCollection<T: Document>: SubCollection<T> {
9797
let document: Element = Element(id: id)
9898
self.remove(document, hard: hard)
9999
}
100+
101+
public override func deleteFiles(_ id: String, container: DeleteContainer? = nil, block: ((Error?) -> Void)? = nil) {
102+
// Do nothing
103+
}
100104
}
101105

Pring/Relation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ extension AnyRelation where Self: HasDocument {
2828
return uploadContainer.tasks
2929
}
3030

31-
public func deleteFiles(container: DeleteContainer?, block: ((Error?) -> Void)?) {
31+
public func deleteFiles(_ id: String, container: DeleteContainer?, block: ((Error?) -> Void)?) {
3232
let deleteContainer: DeleteContainer = container ?? DeleteContainer()
33-
self.deleteFiles(container: deleteContainer, block: nil)
33+
self.deleteFiles(id, container: deleteContainer, block: nil)
3434
}
3535
}
3636

0 commit comments

Comments
 (0)