@@ -64,20 +64,53 @@ internal enum FunctionsConstants {
64
64
*/
65
65
open private( set) var emulatorOrigin : String ?
66
66
67
+ /**
68
+ * Creates a Cloud Functions client or returns a pre-existing instance if it already exists.
69
+ */
70
+ @objc ( functions) open class func functions( ) -> Functions {
71
+ return functions (
72
+ app: FirebaseApp . app ( ) ,
73
+ region: FunctionsConstants . defaultRegion,
74
+ customDomain: nil
75
+ )
76
+ }
77
+
78
+ /**
79
+ * Creates a Cloud Functions client with the given app, or returns a pre-existing
80
+ * instance if one already exists.
81
+ * @param app The app for the Firebase project.
82
+ */
83
+ @objc ( functionsForApp: ) open class func functions( app: FirebaseApp ) -> Functions {
84
+ return functions ( app: app, region: FunctionsConstants . defaultRegion, customDomain: nil )
85
+ }
86
+
87
+ /**
88
+ * Creates a Cloud Functions client with the default app and given region.
89
+ * @param region The region for the http trigger, such as "us-central1".
90
+ */
91
+ @objc ( functionsForRegion: ) open class func functions( region: String ) -> Functions {
92
+ return functions ( app: FirebaseApp . app ( ) , region: region, customDomain: nil )
93
+ }
94
+
95
+ /**
96
+ * Creates a Cloud Functions client with the given app and region, or returns a pre-existing
97
+ * instance if one already exists.
98
+ * @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
99
+ */
100
+ @objc ( functionsForCustomDomain: ) open class func functions( customDomain: String ) -> Functions {
101
+ return functions ( app: FirebaseApp . app ( ) ,
102
+ region: FunctionsConstants . defaultRegion, customDomain: customDomain)
103
+ }
104
+
67
105
/**
68
106
* Creates a Cloud Functions client with the given app and region, or returns a pre-existing
69
107
* instance if one already exists.
70
108
* @param app The app for the Firebase project.
71
109
* @param region The region for the http trigger, such as "us-central1".
72
110
*/
73
- @objc ( functionsForApp: region: ) open class func functions( app: FirebaseApp = FirebaseApp . app ( ) ! ,
111
+ @objc ( functionsForApp: region: ) open class func functions( app: FirebaseApp ,
74
112
region: String ) -> Functions {
75
- let provider = ComponentType< FunctionsProvider> . instance( for: FunctionsProvider . self,
76
- in: app. container)
77
- return provider. functions ( for: app,
78
- region: region,
79
- customDomain: nil ,
80
- type: self )
113
+ return functions ( app: app, region: region, customDomain: nil )
81
114
}
82
115
83
116
/**
@@ -86,14 +119,10 @@ internal enum FunctionsConstants {
86
119
* @param app The app for the Firebase project.
87
120
* @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
88
121
*/
89
- @objc ( functionsForApp: customDomain: ) open class func functions( app: FirebaseApp = FirebaseApp
90
- . app ( ) !,
91
- customDomain: String ? = nil ) -> Functions {
92
- let provider = app. container. instance ( for: FunctionsProvider . self) as? FunctionsProvider
93
- return provider!. functions ( for: app,
94
- region: FunctionsConstants . defaultRegion,
95
- customDomain: customDomain,
96
- type: self )
122
+ @objc ( functionsForApp: customDomain: ) open class func functions( app: FirebaseApp ,
123
+ customDomain: String )
124
+ -> Functions {
125
+ return functions ( app: app, region: FunctionsConstants . defaultRegion, customDomain: customDomain)
97
126
}
98
127
99
128
/**
@@ -158,44 +187,21 @@ internal enum FunctionsConstants {
158
187
emulatorOrigin = origin
159
188
}
160
189
161
- // MARK: - Public APIs only for Objective C
162
-
163
- /**
164
- * Creates a Cloud Functions client or returns a pre-existing instance if it already exists.
165
- */
166
- @objc ( functions) open class func __functions( ) -> Functions {
167
- return functions ( )
168
- }
169
-
170
- /**
171
- * Creates a Cloud Functions client with the given app, or returns a pre-existing
172
- * instance if one already exists.
173
- * @param app The app for the Firebase project.
174
- */
175
- @objc ( functionsForApp: ) open class func __functionsForApp( app: FirebaseApp ) -> Functions {
176
- return functions ( app: app)
177
- }
178
-
179
- /**
180
- * Creates a Cloud Functions client with the default app and given region.
181
- * @param region The region for the http trigger, such as "us-central1".
182
- */
183
- @objc ( functionsForRegion: ) open class func __functionsForRegion( region: String ) -> Functions {
184
- return functions ( region: region)
185
- }
190
+ // MARK: - Private Funcs (or Internal for tests)
186
191
187
- /**
188
- * Creates a Cloud Functions client with the given app and region, or returns a pre-existing
189
- * instance if one already exists.
190
- * @param customDomain A custom domain for the http trigger, such as "https://mydomain.com".
191
- */
192
- @objc ( functionsForCustomDomain: ) open class func __functionsForCustomDomain( customDomain: String ? )
193
- -> Functions {
194
- return functions ( customDomain: customDomain)
192
+ /// Solely used to have one precondition and one location where we fetch from the container. This
193
+ /// previously was avoided due to default arguments but that doesn't work well with Obj-C compatibility.
194
+ private class func functions( app: FirebaseApp ? , region: String ,
195
+ customDomain: String ? ) -> Functions {
196
+ precondition ( app != nil ,
197
+ " `FirebaseApp.configure()` needs to be called before using Functions. " )
198
+ let provider = app!. container. instance ( for: FunctionsProvider . self) as? FunctionsProvider
199
+ return provider!. functions ( for: app!,
200
+ region: region,
201
+ customDomain: customDomain,
202
+ type: self )
195
203
}
196
204
197
- // MARK: - Private Funcs (or Internal for tests)
198
-
199
205
@objc internal init ( projectID: String ,
200
206
region: String ,
201
207
customDomain: String ? ,
0 commit comments