Skip to content

Commit 80df25b

Browse files
committed
Fix some bugs and add implmentation
1 parent 2af2fb2 commit 80df25b

File tree

2 files changed

+101
-6
lines changed

2 files changed

+101
-6
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2020 Google LLC
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 "FIREmulatorSettings.h"
18+
19+
/** :nodoc: */
20+
NSString *const FIREmulatorServiceDatabase = @"FIREmulatorServiceDatabase";
21+
22+
/** :nodoc: */
23+
NSString *const FIREmulatorServiceFirestore = @"FIREmulatorServiceFirestore";
24+
25+
/** :nodoc: */
26+
NSString *const FIREmulatorServiceAuth = @"FIREmulatorServiceAuth";
27+
28+
/** :nodoc: */
29+
NSString *const FIREmulatorServiceFunctions = @"FIREmulatorServiceFunctions";
30+
31+
@implementation FIREmulatorServiceSettings
32+
33+
- (instancetype)init {
34+
NSAssert(NO, @"The default initializer is unavailable. Call the designated initializer instead.");
35+
}
36+
37+
- (instancetype)initWithHost:(NSString *)host port:(NSInteger)port {
38+
NSAssert(host != nil, @"A nonnull host is required");
39+
self = [super init];
40+
if (self != nil) {
41+
_host = [host copy];
42+
_port = port;
43+
}
44+
return self;
45+
}
46+
47+
- (instancetype)copyWithZone:(NSZone *)zone {
48+
return self; // instances are immutable, so return self
49+
}
50+
51+
@end
52+
53+
@interface FIREmulatorSettings ()
54+
55+
@property(nonatomic, copy, nonnull)
56+
NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *settings;
57+
58+
@end
59+
60+
@implementation FIREmulatorSettings
61+
62+
- (instancetype)init {
63+
NSAssert(NO, @"The default initializer is unavailable. Call the designated initializer instead.");
64+
}
65+
66+
- (instancetype)initWithSettings:
67+
(NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *)settings {
68+
NSAssert(settings.count > 0,
69+
@"Creating emulator settings requires non-empty service settings list.");
70+
self = [super init];
71+
if (self != nil) {
72+
_settings = [settings copy];
73+
}
74+
return self;
75+
}
76+
77+
- (instancetype)initWithServiceSettings:(FIREmulatorServiceSettings *)settings
78+
forService:(FIREmulatorService *)service {
79+
NSAssert(settings != nil);
80+
NSAssert(service != nil);
81+
NSDictionary *settings = @{service : settings};
82+
return [self initWithSettings:settings];
83+
}
84+
85+
- (instancetype)copyWithZone:(NSZone *)zone {
86+
return self; // immutable, so return self
87+
}
88+
89+
- (FIREmulatorSettings *)settingsForService:(FIREmulatorService *)service {
90+
return self.settings[service];
91+
}
92+
93+
@end

FirebaseCore/Sources/Public/FIREmulatorSettings.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import Foundation
17+
#import <Foundation/Foundation.h>
1818

1919
NS_ASSUME_NONNULL_BEGIN
2020

@@ -35,13 +35,13 @@ NSString *const FIREmulatorServiceFunctions;
3535

3636
/// A class representing the connection settings for an emulated Firebase service.
3737
NS_SWIFT_NAME(EmulatorServiceSettings)
38-
@interface FIREmulatorServiceSettings: NSObject <NSCopying>
38+
@interface FIREmulatorServiceSettings : NSObject <NSCopying>
3939

4040
/// The host of the emulated service, "localhost" for example.
41-
@property (nonatomic, readonly) NSString *host;
41+
@property(nonatomic, readonly) NSString *host;
4242

4343
/// The port number of the emulated service.
44-
@property (nonatomic, readonly) NSInteger port;
44+
@property(nonatomic, readonly) NSInteger port;
4545

4646
/// Creates a new instance with the specified host name and port number.
4747
- (instancetype)initWithHost:(NSString *)host port:(NSInteger)port NS_DESIGNATED_INITIALIZER;
@@ -53,15 +53,17 @@ NS_SWIFT_NAME(EmulatorServiceSettings)
5353

5454
/// A class representing per-app settings for emulated Firebase services.
5555
NS_SWIFT_NAME(EmulatorSettings)
56-
@interface FIREmulatorSettings: NSObject <NSCopying>
56+
@interface FIREmulatorSettings : NSObject <NSCopying>
5757

5858
/// Initializes an app-level settings instance with the given emulator service settings.
5959
- (instancetype)initWithServiceSettings:(FIREmulatorServiceSettings *)settings
6060
forService:(FIREmulatorService *)service;
6161

6262
/// Initializes an app-level settings instance with all of the provided settings.
6363
/// The provided settings dictionary must not be empty.
64-
- (instancetype)initWithSettings:(NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *)settings NS_DESIGNATED_INITIALIZER;
64+
- (instancetype)initWithSettings:
65+
(NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *)settings
66+
NS_DESIGNATED_INITIALIZER;
6567

6668
/// Returns the service-level settings object for a given emulated service, if it exists.
6769
- (FIREmulatorSettings *_Nullable)settingsForService:(FIREmulatorService *)service;

0 commit comments

Comments
 (0)