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
weakto 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() -> BoolReturn Value
trueif the flags are loaded and ready for use,falseotherwise. -
Synchronously retrieves the complete
MixpanelFlagVariantfor a given flag name. If the feature flag is found and flags are ready, its variant is returned. Otherwise, the providedfallbackMixpanelFlagVariantis returned. This method will also trigger any necessary tracking logic for the accessed flag.Declaration
Swift
func getVariantSync(_ flagName: String, fallback: MixpanelFlagVariant) -> MixpanelFlagVariantParameters
flagNameThe unique identifier for the feature flag.
fallbackThe
MixpanelFlagVariantto return if the specified flag is not found or if the flags are not yet loaded.Return Value
The
MixpanelFlagVariantassociated withflagName, or thefallbackvariant. -
Asynchronously retrieves the complete
MixpanelFlagVariantfor a given flag name. If flags are not ready, an attempt will be made to load them. Thecompletionhandler is called with theMixpanelFlagVariantfor the flag, or thefallbackvariant 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
flagNameThe unique identifier for the feature flag.
fallbackThe
MixpanelFlagVariantto use as a default if the specified flag is not found or an error occurs during fetching.completionA 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
valueproperty from theMixpanelFlagVariantobtained viagetVariantSync.Declaration
Swift
func getVariantValueSync(_ flagName: String, fallbackValue: Any?) -> Any?Parameters
flagNameThe unique identifier for the feature flag.
fallbackValueThe 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
valueproperty from theMixpanelFlagVariantobtained viagetVariant. If flags are not ready, an attempt will be made to load them. Thecompletionhandler 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
flagNameThe unique identifier for the feature flag.
fallbackValueThe default value to use if the flag is not found, fetching fails, or its variant doesn’t contain a value.
completionA 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) -> BoolParameters
flagNameThe unique identifier for the feature flag.
fallbackValueThe 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
trueif the flag is considered enabled,falseotherwise (including iffallbackValueis 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
completionhandler 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
flagNameThe unique identifier for the feature flag.
fallbackValueThe boolean value to use if the flag is not found, fetching fails, or it cannot be evaluated as a boolean. Defaults to
false.completionA closure that is called with the boolean result. This closure will be executed on the main dispatch queue.
View on GitHub
MixpanelFlags Protocol Reference