MixpanelFlags
public protocol MixpanelFlags
A protocol defining the public interface for a feature flagging system.
-
The delegate responsible for handling feature flag lifecycle events, such as tracking. It is declared
weak
to prevent retain cycles.Declaration
Swift
var delegate: MixpanelFlagDelegate? { get set }
-
Initiates the loading or refreshing of flags
Declaration
Swift
func loadFlags()
-
Synchronously checks if the flags have been successfully loaded and are available for querying.
Declaration
Swift
func areFlagsReady() -> Bool
Return Value
true
if the flags are loaded and ready for use,false
otherwise. -
Synchronously retrieves the complete
MixpanelFlagVariant
for a given flag name. If the feature flag is found and flags are ready, its variant is returned. Otherwise, the providedfallback
MixpanelFlagVariant
is returned. This method will also trigger any necessary tracking logic for the accessed flag.Declaration
Swift
func getVariantSync(_ flagName: String, fallback: MixpanelFlagVariant) -> MixpanelFlagVariant
Parameters
flagName
The unique identifier for the feature flag.
fallback
The
MixpanelFlagVariant
to return if the specified flag is not found or if the flags are not yet loaded.Return Value
The
MixpanelFlagVariant
associated withflagName
, or thefallback
variant. -
Asynchronously retrieves the complete
MixpanelFlagVariant
for a given flag name. If flags are not ready, an attempt will be made to load them. Thecompletion
handler is called with theMixpanelFlagVariant
for the flag, or thefallback
variant if the flag is not found or loading fails. This method will also trigger any necessary tracking logic for the accessed flag. The completion handler is typically invoked on the main thread.Declaration
Swift
func getVariant(_ flagName: String, fallback: MixpanelFlagVariant, completion: @escaping (MixpanelFlagVariant) -> Void)
Parameters
flagName
The unique identifier for the feature flag.
fallback
The
MixpanelFlagVariant
to use as a default if the specified flag is not found or an error occurs during fetching.completion
A closure that is called with the resulting
MixpanelFlagVariant
. This closure will be executed on the main dispatch queue. -
Synchronously retrieves the underlying value of a feature flag. This is a convenience method that extracts the
value
property from theMixpanelFlagVariant
obtained viagetVariantSync
.Declaration
Swift
func getVariantValueSync(_ flagName: String, fallbackValue: Any?) -> Any?
Parameters
flagName
The unique identifier for the feature flag.
fallbackValue
The default value to return if the flag is not found, its variant doesn’t contain a value, or flags are not ready.
Return Value
The value of the feature flag, or
fallbackValue
. The type isAny?
. -
Asynchronously retrieves the underlying value of a feature flag. This is a convenience method that extracts the
value
property from theMixpanelFlagVariant
obtained viagetVariant
. If flags are not ready, an attempt will be made to load them. Thecompletion
handler is called with the flag’s value or thefallbackValue
. The completion handler is typically invoked on the main thread.Declaration
Swift
func getVariantValue(_ flagName: String, fallbackValue: Any?, completion: @escaping (Any?) -> Void)
Parameters
flagName
The unique identifier for the feature flag.
fallbackValue
The default value to use if the flag is not found, fetching fails, or its variant doesn’t contain a value.
completion
A closure that is called with the resulting value (
Any?
). This closure will be executed on the main dispatch queue. -
Synchronously checks if a specific feature flag is considered “enabled”. This typically involves retrieving the flag’s value and evaluating it as a boolean. The exact logic for what constitutes “enabled” (e.g.,
true
, non-nil, a specific string) should be defined by the implementing class.Declaration
Swift
func isEnabledSync(_ flagName: String, fallbackValue: Bool) -> Bool
Parameters
flagName
The unique identifier for the feature flag.
fallbackValue
The boolean value to return if the flag is not found, cannot be evaluated as a boolean, or flags are not ready. Defaults to
false
.Return Value
true
if the flag is considered enabled,false
otherwise (including iffallbackValue
is used). -
Asynchronously checks if a specific feature flag is considered “enabled”. This typically involves retrieving the flag’s value and evaluating it as a boolean. If flags are not ready, an attempt will be made to load them. The
completion
handler is called with the boolean result. The completion handler is typically invoked on the main thread.Declaration
Swift
func isEnabled(_ flagName: String, fallbackValue: Bool, completion: @escaping (Bool) -> Void)
Parameters
flagName
The unique identifier for the feature flag.
fallbackValue
The boolean value to use if the flag is not found, fetching fails, or it cannot be evaluated as a boolean. Defaults to
false
.completion
A closure that is called with the boolean result. This closure will be executed on the main dispatch queue.