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() -
Initiates the loading or refreshing of flags with a completion callback. The completion handler is called with
trueon success andfalseon failure.Declaration
Swift
func loadFlags(completion: ((Bool) -> Void)?) -
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.Important
This method may block the calling thread until the value can be retrieved. It is NOT recommended to call this from the main UI thread. If flags are not ready (
areFlagsReady()is false), this method returns thefallbackvalue, but it may still block while waiting for queued tracking or activation work to complete. If called immediately after track(), variants may not be activated yet due to a race condition as track is executed asynchronously. UsegetVariantinstead.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.Important
This method may block the calling thread until the value can be retrieved. It is NOT recommended to call this from the main UI thread. If flags are not ready (
areFlagsReady()is false), this method returns thefallbackValue, but it may still block while waiting for queued tracking or activation work to complete. If called immediately after track(), variants may not be activated yet due to a race condition as track is executed asynchronously. UsegetVariantValueinstead.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.Important
This method may block the calling thread until the value can be retrieved. It is NOT recommended to call this from the main UI thread. If flags are not ready (
areFlagsReady()is false), this method returns thefallbackValue, but it may still block while waiting for queued tracking or activation work to complete.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.
-
Synchronously retrieves all currently fetched feature flag variants. Returns an empty dictionary if flags have not been loaded yet. This method does not trigger tracking for any flags.
Important
This method may block the calling thread until the value can be retrieved. It is NOT recommended to call this from the main UI thread. If flags are not ready (
areFlagsReady()is false), it returns an empty dictionary immediately without fetching, but it may still block while waiting for queued tracking or activation work to complete. If called immediately after track(), variants may not be activated yet due to a race condition as track is executed asynchronously. UsegetAllVariantsinstead.Declaration
Swift
func getAllVariantsSync() -> [String : MixpanelFlagVariant]Return Value
A dictionary mapping flag names to their
MixpanelFlagVariantvalues, or an empty dictionary if flags are not ready. -
Asynchronously retrieves all feature flag variants. If flags are not ready, an attempt will be made to load them. This method does not trigger tracking for any flags. The completion handler is typically invoked on the main thread.
Declaration
Swift
func getAllVariants(completion: @escaping ([String : MixpanelFlagVariant]) -> Void)Parameters
completionA closure that is called with a dictionary mapping flag names to their
MixpanelFlagVariantvalues. Returns an empty dictionary if fetching fails. -
Replaces the current custom flag evaluation context entirely and triggers a flag re-fetch.
Declaration
Swift
func setContext(_ context: [String : Any], completion: @escaping () -> Void)Parameters
contextThe new context dictionary to use for flag evaluation.
completionA closure called when the fetch completes (success or failure).
View on GitHub
Install in Dash