UserMetadata.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. /** @class UserMetadata
  16. @brief A data class representing the metadata corresponding to a Firebase user.
  17. */
  18. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  19. extension UserMetadata: NSSecureCoding {}
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. @objc(FIRUserMetadata) open class UserMetadata: NSObject {
  22. /** @property lastSignInDate
  23. @brief Stores the last sign in date for the corresponding Firebase user.
  24. */
  25. @objc public let lastSignInDate: Date?
  26. /** @property creationDate
  27. @brief Stores the creation date for the corresponding Firebase user.
  28. */
  29. @objc public let creationDate: Date?
  30. init(withCreationDate creationDate: Date?, lastSignInDate: Date?) {
  31. self.creationDate = creationDate
  32. self.lastSignInDate = lastSignInDate
  33. }
  34. // MARK: Secure Coding
  35. private static let kCreationDateCodingKey = "creationDate"
  36. private static let kLastSignInDateCodingKey = "lastSignInDate"
  37. public static var supportsSecureCoding: Bool {
  38. return true
  39. }
  40. public func encode(with coder: NSCoder) {
  41. coder.encode(creationDate, forKey: UserMetadata.kCreationDateCodingKey)
  42. coder.encode(lastSignInDate, forKey: UserMetadata.kLastSignInDateCodingKey)
  43. }
  44. public required convenience init?(coder: NSCoder) {
  45. let creationDate = coder.decodeObject(of: [NSDate.self],
  46. forKey: UserMetadata.kCreationDateCodingKey)
  47. let lastSignInDate = coder.decodeObject(of: [NSDate.self],
  48. forKey: UserMetadata.kLastSignInDateCodingKey)
  49. self.init(withCreationDate: creationDate as? Date, lastSignInDate: lastSignInDate as? Date)
  50. }
  51. }