Geen omschrijving

FIRUserMetadata.m 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "FIRUserMetadata_Internal.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. @implementation FIRUserMetadata
  19. /** @var kCreationDateCodingKey
  20. @brief The key used to encode the creationDate property for NSSecureCoding.
  21. */
  22. static NSString *const kCreationDateCodingKey = @"creationDate";
  23. /** @var kLastSignInDateCodingKey
  24. @brief The key used to encode the lastSignInDate property for NSSecureCoding.
  25. */
  26. static NSString *const kLastSignInDateCodingKey = @"lastSignInDate";
  27. - (instancetype)initWithCreationDate:(nullable NSDate *)creationDate
  28. lastSignInDate:(nullable NSDate *)lastSignInDate {
  29. self = [super init];
  30. if (self) {
  31. _creationDate = [creationDate copy];
  32. _lastSignInDate = [lastSignInDate copy];
  33. }
  34. return self;
  35. }
  36. #pragma mark - NSSecureCoding
  37. + (BOOL)supportsSecureCoding {
  38. return YES;
  39. }
  40. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  41. NSDate *creationDate =
  42. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kCreationDateCodingKey];
  43. NSDate *lastSignInDate =
  44. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kLastSignInDateCodingKey];
  45. return [self initWithCreationDate:creationDate lastSignInDate:lastSignInDate];
  46. }
  47. - (void)encodeWithCoder:(NSCoder *)aCoder {
  48. [aCoder encodeObject:_creationDate forKey:kCreationDateCodingKey];
  49. [aCoder encodeObject:_lastSignInDate forKey:kLastSignInDateCodingKey];
  50. }
  51. @end
  52. NS_ASSUME_NONNULL_END