Hi everyone,
I'm working on a Swift application and trying to determine whether an application has exceeded its limit based on an ApplicationToken
. I have the following function to check if the current app's token matches any of the tokens stored when the app limit is reached:
private func isAppLimitExceeded(for application: Application?) -> Bool {
guard let application = application, let appToken = application.token else { return false }
let exceededTokens = configManager.getAppLimitExceededTokens()
return exceededTokens.contains { exceededToken in
appToken == exceededToken
}
}
The function configManager.getAppLimitExceededTokens()
returns a list of [ApplicationToken]
that were saved in UserDefaults
when an app limit is reached. The goal is to use the isAppLimitExceeded
method to verify if the current shield for the app is triggered due to a limit/threshold being exceeded.
This function is part of a class that conforms to the ShieldConfigurationDataSource
protocol:
class ShieldConfigurationExtension: ShieldConfigurationDataSource {
// ...
}
My concern is whether comparing two ApplicationToken
instances using ==
is a reliable method for determining if they are equal.
- Are
ApplicationToken
objects guaranteed to be comparable with==
out of the box, or do I need to implementEquatable
or another method of comparison? - Could there be issues with tokens stored in
UserDefaults
not matching due to reference or serialization differences?
Any guidance on how to ensure proper comparison of these tokens would be appreciated!
Thanks!