UserMetadata.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. @objc(FIRUserMetadata) public class UserMetadata: NSObject, NSSecureCoding {
  19. /** @property lastSignInDate
  20. @brief Stores the last sign in date for the corresponding Firebase user.
  21. */
  22. @objc public let lastSignInDate: Date?
  23. /** @property creationDate
  24. @brief Stores the creation date for the corresponding Firebase user.
  25. */
  26. @objc public let creationDate: Date?
  27. // TODO: Nothing public below here
  28. @objc public init(withCreationDate creationDate: Date?, lastSignInDate: Date?) {
  29. self.creationDate = creationDate
  30. self.lastSignInDate = lastSignInDate
  31. }
  32. // MARK: Secure Coding
  33. private static let kCreationDateCodingKey = "creationDate"
  34. private static let kLastSignInDateCodingKey = "lastSignInDate"
  35. public static var supportsSecureCoding: Bool {
  36. return true
  37. }
  38. public func encode(with coder: NSCoder) {
  39. coder.encode(creationDate, forKey: UserMetadata.kCreationDateCodingKey)
  40. coder.encode(lastSignInDate, forKey: UserMetadata.kLastSignInDateCodingKey)
  41. }
  42. public required convenience init?(coder: NSCoder) {
  43. let creationDate = coder.decodeObject(of: [NSDate.self],
  44. forKey: UserMetadata.kCreationDateCodingKey) as? Date
  45. let lastSignInDate = coder.decodeObject(of: [NSDate.self],
  46. forKey: UserMetadata.kLastSignInDateCodingKey) as? Date
  47. self.init(withCreationDate: creationDate, lastSignInDate: lastSignInDate)
  48. }
  49. }