@@ -75,36 +75,42 @@ The Swift names are identical but dropping the `FIR` prefix.
75
75
offered, dependencies, and a block for Core to instantiate it.
76
76
- ` @class FIRComponentContainer `
77
77
- A container that holds different components that are registered with Core.
78
- - ` @protocol FIRComponentRegistrant `
79
- - Describes functionality for frameworks registering components in the ` FIRComponentContainer ` . It
80
- allows Core to fetch components lazily from the implementing framework.
81
78
- ` #define FIR_COMPONENT(protocol, container) ` (macro)
82
79
- The macro to request an instance conforming to a given protocol from a container. Due to
83
80
Objective-C's lightweight generic system, the safest and most readable API is provided by a
84
81
macro that uses internal types to give compiler warnings if a developer tries to assign the
85
82
result to a variable with the incorrect type.
83
+ - ` @protocol FIRLibrary `
84
+ - Describes functionality for frameworks registering components in the ` FIRComponentContainer ` as
85
+ well as other Core configuration functionality. It allows Core to fetch components lazily from
86
+ the implementing framework.
87
+
86
88
87
89
## Registering with Core
88
90
89
91
Each Firebase framework should register with Core in the ` +load ` method of the class conforming to
90
- ` FIRComponentRegistrant ` . This needs to happen at ` +load ` time because Core needs to resolve any
92
+ ` FIRLibrary ` . This needs to happen at ` +load ` time because Core needs to resolve any
91
93
dependencies before a class has a chance to be called by a developer (if called at all).
92
94
93
95
```
96
+ #import <FirebaseCore/FIRAppInternal.h>
94
97
#import <FirebaseCore/FIRComponentContainer.h>
95
- #import <FirebaseCore/FIRComponentRegistrant .h>
98
+ #import <FirebaseCore/FIRLibrary .h>
96
99
97
- @interface FIRFoo <FIRComponentRegistrant >
100
+ @interface FIRFoo <FIRLibrary >
98
101
@end
99
102
100
103
@implementation FIRFoo
101
104
102
105
+ (void)load {
103
- // Register with Core's container.
104
- [FIRComponentContainer registerAsComponentRegistrant:self];
106
+ // Register with Core as a library. The version should be fetched from a constant defined
107
+ // elsewhere, but that's not covered or relevant for this example.
108
+ [FIRApp registerInternalLibrary:self
109
+ withName:"fire-foo"
110
+ withVersion:"1.0.0"];
105
111
}
106
112
107
- // TODO: Conform to `FIRComponentRegistrant `. See later sections for more information.
113
+ // TODO: Conform to `FIRLibrary `. See later sections for more information.
108
114
109
115
@end
110
116
```
@@ -131,20 +137,21 @@ it. It has a private, empty protocol that it uses to register with the container
131
137
an example:
132
138
133
139
```
134
- // FIRFunctions.h
140
+ // FIRFunctions.m
135
141
136
142
/// Empty protocol to register Functions as a component with Core.
137
143
@protocol FIRFunctionsInstanceProvider
138
144
@end
139
145
140
146
/// Privately conform to the protocol for component registration.
141
- @interface FIRFunctions () <FIRFunctionsInstanceProvider, FIRComponentRegistrant >
147
+ @interface FIRFunctions () <FIRFunctionsInstanceProvider, FIRLibrary >
142
148
@end
143
149
144
150
@implementation FIRFunctions
145
151
146
152
+ (void)load {
147
- [FIRComponentContainer registerAsComponentRegistrant:self];
153
+ NSString *version = <# Fetch the version here #>;
154
+ [FIRApp registerInternalLibrary:self withName:"fire-fun" withVersion:version];
148
155
}
149
156
150
157
/// The array of components to register with Core. Since Functions is a leaf node and
@@ -207,9 +214,15 @@ could conform to and provide to other frameworks:
207
214
// FIRAuth.m in the FirebaseAuth framework.
208
215
209
216
/// Privately conform to the protocol for interop and component registration.
210
- @interface FIRAuth () <FIRAuthInteroperable, FIRComponentRegistrant >
217
+ @interface FIRAuth () <FIRAuthInteroperable, FIRLibrary >
211
218
@end
212
219
220
+ + (void)load {
221
+ // Remember to register in +load!
222
+ NSString *version = <# Fetch the version here #>;
223
+ [FIRApp registerInternalLibrary:self withName:"fire-auth" withVersion:version];
224
+ }
225
+
213
226
/// The components to register with Core.
214
227
+ (NSArray<FIRComponent *> *)componentsToRegister {
215
228
// Provide a component that will return an instance of `FIRAuth`.
@@ -258,8 +271,7 @@ separate class to keep `Firestore.m` cleaner.
258
271
259
272
```
260
273
/// A concrete implementation for FSTFirestoreMultiDBProvider to create Firestore instances.
261
- @interface FSTFirestoreComponent : NSObject <FSTFirestoreMultiDBProvider,
262
- FIRComponentRegistrant>
274
+ @interface FSTFirestoreComponent : NSObject <FSTFirestoreMultiDBProvider, FIRLibrary>
263
275
264
276
/// The `FIRApp` that instances will be set up with.
265
277
@property(nonatomic, weak, readonly) FIRApp *app;
@@ -281,8 +293,9 @@ separate class to keep `Firestore.m` cleaner.
281
293
@synthesize instances = _instances;
282
294
283
295
+ (void)load {
284
- // Don't forget to register!
285
- [FIRComponentContainer registerAsComponentRegistrant:self];
296
+ // Remember to register in +load!
297
+ NSString *version = <# Fetch the version here #>;
298
+ [FIRApp registerInternalLibrary:self withName:"fire-fst" withVersion:version];
286
299
}
287
300
288
301
- (instancetype)initWithApp:(FIRApp *)app {
@@ -299,7 +312,7 @@ separate class to keep `Firestore.m` cleaner.
299
312
// Regular initialization code to create Firestore instances with required parameters...
300
313
}
301
314
302
- // `FIRComponentRegistrant ` conformance.
315
+ // `FIRLibrary ` conformance.
303
316
+ (NSArray<FIRComponent *> *)componentsToRegister {
304
317
// Ignore any dependencies for simplicity in this example.
305
318
FIRComponentCreationBlock creationBlock =
0 commit comments