added iOS source code
[wl-app.git] / iOS / Pods / FirebaseCore / Firebase / Core / Private / FIRComponent.h
1 /*
2  * Copyright 2018 Google
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #import <Foundation/Foundation.h>
18
19 @class FIRApp;
20 @class FIRComponentContainer;
21
22 NS_ASSUME_NONNULL_BEGIN
23
24 /// Provides a system to clean up cached instances returned from the component system.
25 NS_SWIFT_NAME(ComponentLifecycleMaintainer)
26 @protocol FIRComponentLifecycleMaintainer
27 /// The associated app will be deleted, clean up any resources as they are about to be deallocated.
28 - (void)appWillBeDeleted:(FIRApp *)app;
29 @end
30
31 typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container,
32                                                   BOOL *isCacheable)
33     NS_SWIFT_NAME(ComponentCreationBlock);
34
35 @class FIRDependency;
36
37 /// Describes the timing of instantiation. Note: new components should default to lazy unless there
38 /// is a strong reason to be eager.
39 typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
40   FIRInstantiationTimingLazy,
41   FIRInstantiationTimingAlwaysEager,
42   FIRInstantiationTimingEagerInDefaultApp
43 } NS_SWIFT_NAME(InstantiationTiming);
44
45 /// A component that can be used from other Firebase SDKs.
46 NS_SWIFT_NAME(Component)
47 @interface FIRComponent : NSObject
48
49 /// The protocol describing functionality provided from the Component.
50 @property(nonatomic, strong, readonly) Protocol *protocol;
51
52 /// The timing of instantiation.
53 @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
54
55 /// An array of dependencies for the component.
56 @property(nonatomic, copy, readonly) NSArray<FIRDependency *> *dependencies;
57
58 /// A block to instantiate an instance of the component with the appropriate dependencies.
59 @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
60
61 // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
62 // for the next two methods.
63 // clang-format off
64
65 /// Creates a component with no dependencies that will be lazily initialized.
66 + (instancetype)componentWithProtocol:(Protocol *)protocol
67                         creationBlock:(FIRComponentCreationBlock)creationBlock
68 NS_SWIFT_NAME(init(_:creationBlock:));
69
70 /// Creates a component to be registered with the component container.
71 ///
72 /// @param protocol - The protocol describing functionality provided by the component.
73 /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
74 ///                              a good reason to be instantiated earlier.
75 /// @param dependencies - Any dependencies the `implementingClass` has, optional or required.
76 /// @param creationBlock - A block to instantiate the component with a container, and if
77 /// @return A component that can be registered with the component container.
78 + (instancetype)componentWithProtocol:(Protocol *)protocol
79                   instantiationTiming:(FIRInstantiationTiming)instantiationTiming
80                          dependencies:(NSArray<FIRDependency *> *)dependencies
81                         creationBlock:(FIRComponentCreationBlock)creationBlock
82 NS_SWIFT_NAME(init(_:instantiationTiming:dependencies:creationBlock:));
83
84 // clang-format on
85
86 /// Unavailable.
87 - (instancetype)init NS_UNAVAILABLE;
88
89 @end
90
91 NS_ASSUME_NONNULL_END