-
Notifications
You must be signed in to change notification settings - Fork 1
/
FIRFirestore+Convenience.m
66 lines (49 loc) · 1.61 KB
/
FIRFirestore+Convenience.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// FIRFirestore+Convenience.m
// YoCard
//
// Created by Alexander Ivanov on 09.05.2018.
// Copyright © 2018 Alexander Ivanov. All rights reserved.
//
#import "FIRFirestore+Convenience.h"
@implementation FIRFirestore (Convenience)
@end
@implementation FIRCollectionReference (Convenience)
- (void)getDocuments:(void(^)(FIRQuerySnapshot *))completion {
[self getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (completion)
completion(snapshot);
[error log:@"getDocumentsWithCompletion:"];
}];
}
@end
@implementation FIRDocumentReference (Convenience)
- (void)getDocument:(void (^)(FIRDocumentSnapshot *))completion {
[self getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (completion)
completion(snapshot);
[error log:@"getDocumentWithCompletion:"];
}];
}
- (void)set:(NSDictionary<NSString *,id> *)documentData completion:(void (^)(BOOL))completion {
[self setData:documentData completion:^(NSError * _Nullable error) {
if (completion)
completion(error == Nil);
[error log:@"setData:"];
}];
}
- (void)merge:(NSDictionary<NSString *,id> *)documentData completion:(void (^)(BOOL))completion {
[self setData:documentData options:[FIRSetOptions merge] completion:^(NSError * _Nullable error) {
if (completion)
completion(error == Nil);
[error log:@"setData:"];
}];
}
- (void)update:(NSDictionary<id,id> *)fields completion:(void (^)(BOOL))completion {
[self updateData:fields completion:^(NSError * _Nullable error) {
if (completion)
completion(error == Nil);
[error log:@"updateData:"];
}];
}
@end