mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
### Motivation: Initially I wanted to make `SubscriberAttribute.asDictionary` work using `Codable`. However, this isn't the right refactor because we need the actual raw types to be encoded inside `UserDefaults`. At least this refactor provides several improvements: ### Changes: - `SubscriberAttribute` now has value semantics - ⚠️ `SubscriberAttribute.isSynced` used to be mutable, with reference semantics, which was dangerous - `SubscriberAttribute: Equatable` implementation is now automatic - Cleaned up `SubscriberAttribute.asDictionary` implementation, extracting keys into an `enum` - Moved `Dictionary` -> `SubscriberAttribute` creation to the type itself - ⚠️ `SubscriberAttribute.init(dictionary:)` returns an `Optional` instead of using force-unwrap, avoiding potential crashes - Added more serialization / deserialization tests - Removed `SubscriberAttributesMarshaller` and moved method into `SubscriberAttribute` extension - Moved `SubscriberAttributeDict` into `SubscriberAttribute.Dictionary`
32 lines
646 B
Swift
32 lines
646 B
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// Date+Extensions.swift
|
|
//
|
|
// Created by Josh Holtz on 6/28/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension NSDate {
|
|
|
|
func millisecondsSince1970AsUInt64() -> UInt64 {
|
|
return (self as Date).millisecondsSince1970AsUInt64()
|
|
}
|
|
|
|
}
|
|
|
|
extension Date {
|
|
|
|
func millisecondsSince1970AsUInt64() -> UInt64 {
|
|
return UInt64(self.timeIntervalSince1970 * 1000.0)
|
|
}
|
|
|
|
}
|