-
Notifications
You must be signed in to change notification settings - Fork 7
/
EasyFirebase.swift
91 lines (71 loc) 路 2.02 KB
/
EasyFirebase.swift
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// EasyFirebase.swift
//
//
// Created by Ben Myers on 10/29/21.
//
import Foundation
import Firebase
/**
Thanks for using EasyFirebase! 馃帀
EasyFirebase supports multiple Firebase services, including:
- ``EasyFirestore``
- ``EasyAuth``
- ``EasyStorage``
- ``EasyMessaging``
Additionally, you can set some module-wide settings here, including:
- ``logLevel-swift.type.property``
- ``useCache``
*/
public struct EasyFirebase {
// MARK: - Public Static Properties
/// How detailed Firestore console out.
public static var logLevel: LogLevel = .none
/// Whether the cache should be used.
public static var useCache: Bool = true
// MARK: - Public Static Methods
/**
Prepares `EasyFirebase` and `Firebase`.
鈿狅笍 **Important!** You should *always* call this method at the launch of your program when using any part of `EasyFirebase`.
*/
public static func configure(options: FirebaseOptions? = nil) {
if let options = options {
FirebaseApp.configure(options: options)
} else {
FirebaseApp.configure()
}
if #available(iOS 13.0, *) {
EasyFirestore.db.settings.isPersistenceEnabled = EasyFirestore.usePersistence
}
if #available(iOS 13.0, *) {
EasyAuth.prepare()
}
}
// MARK: - Internal Static Methods
internal static func log(error: Any?) {
guard logLevel.rawValue >= 1 else { return }
if let error = error as? Error {
print("[EasyFirebase] \(error.localizedDescription)")
} else if let error = error {
print("[EasyFirebase]", error)
}
}
internal static func log(_ item: Any?) {
guard logLevel.rawValue >= 2 else { return }
if let item = item {
print("[EasyFirebase]", item)
}
}
// MARK: - Public Enumerations
/**
The log level for Firebase-related output.
*/
public enum LogLevel: Int {
/// Don't log any output.
case none = 0
/// Only log errors.
case errors = 1
/// Log errors and transfer messages.
case all = 2
}
}