FIRFirestoreSettings.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2017 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. #import "FIRFirestoreSettings.h"
  17. #import "Firestore/Source/Util/FSTUsageValidation.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. static NSString *const kDefaultHost = @"firestore.googleapis.com";
  20. static const BOOL kDefaultSSLEnabled = YES;
  21. static const BOOL kDefaultPersistenceEnabled = YES;
  22. @implementation FIRFirestoreSettings
  23. - (instancetype)init {
  24. if (self = [super init]) {
  25. _host = kDefaultHost;
  26. _sslEnabled = kDefaultSSLEnabled;
  27. _dispatchQueue = dispatch_get_main_queue();
  28. _persistenceEnabled = kDefaultPersistenceEnabled;
  29. }
  30. return self;
  31. }
  32. - (BOOL)isEqual:(id)other {
  33. if (self == other) {
  34. return YES;
  35. } else if (![other isKindOfClass:[FIRFirestoreSettings class]]) {
  36. return NO;
  37. }
  38. FIRFirestoreSettings *otherSettings = (FIRFirestoreSettings *)other;
  39. return [self.host isEqual:otherSettings.host] &&
  40. self.isSSLEnabled == otherSettings.isSSLEnabled &&
  41. self.dispatchQueue == otherSettings.dispatchQueue &&
  42. self.isPersistenceEnabled == otherSettings.isPersistenceEnabled;
  43. }
  44. - (NSUInteger)hash {
  45. NSUInteger result = [self.host hash];
  46. result = 31 * result + (self.isSSLEnabled ? 1231 : 1237);
  47. // Ignore the dispatchQueue to avoid having to deal with sizeof(dispatch_queue_t).
  48. result = 31 * result + (self.isPersistenceEnabled ? 1231 : 1237);
  49. return result;
  50. }
  51. - (id)copyWithZone:(nullable NSZone *)zone {
  52. FIRFirestoreSettings *copy = [[FIRFirestoreSettings alloc] init];
  53. copy.host = _host;
  54. copy.sslEnabled = _sslEnabled;
  55. copy.dispatchQueue = _dispatchQueue;
  56. copy.persistenceEnabled = _persistenceEnabled;
  57. return copy;
  58. }
  59. - (void)setHost:(NSString *)host {
  60. if (!host) {
  61. FSTThrowInvalidArgument(
  62. @"host setting may not be nil. You should generally just use the default value "
  63. "(which is %@)",
  64. kDefaultHost);
  65. }
  66. _host = [host mutableCopy];
  67. }
  68. - (void)setDispatchQueue:(dispatch_queue_t)dispatchQueue {
  69. if (!dispatchQueue) {
  70. FSTThrowInvalidArgument(
  71. @"dispatch queue setting may not be nil. Create a new dispatch queue with "
  72. "dispatch_queue_create(\"com.example.MyQueue\", NULL) or just use the default "
  73. "(which is the main queue, returned from dispatch_get_main_queue())");
  74. }
  75. _dispatchQueue = dispatchQueue;
  76. }
  77. @end
  78. NS_ASSUME_NONNULL_END