BasicModuleFactory

public class BasicModuleFactory<Module> : ModuleFactory where Module : BasicModule

A basic factory that can be reused to create modules that have no extra dependencies and can only be initialized once.

BasicModuleFactory is a generic implementation of ModuleFactory that simplifies the creation of modules conforming to the BasicModule protocol.

For detailed guidance on creating custom modules, see Creating Custom Modules.

## Important Notes

  • The generic Module type must conform to BasicModule
  • Modules created by this factory cannot be instantiated multiple times (allowsMultipleInstances is always false)
  • Use ModuleSettingsBuilder subclasses for type-safe configuration
  • Module type constants should be defined in Modules.Types for consistency
  • The unique identifier for the type of module this factory creates.

    Declaration

    Swift

    public let moduleType: String
  • Always false for BasicModuleFactory - modules can only be instantiated once.

    Declaration

    Swift

    public let allowsMultipleInstances: Bool
  • Creates a new BasicModuleFactory for the specified module type.

    Declaration

    Swift

    public init(moduleType: String, enforcedSettings: DataObject? = nil)

    Parameters

    moduleType

    A unique string identifier for the module type. This should match the module type used in settings and configuration.

    enforcedSettings

    Optional settings that will be enforced for this module, overriding any local or remote settings. If provided, the module will be initialized even without additional configuration. If nil, the module will only be initialized when local or remote settings are available.

  • Creates a new instance of the module with the provided configuration.

    This method delegates to the module’s required initializer, passing the context and configuration. The module can return nil if initialization fails due to invalid or insufficient configuration.

    Declaration

    Swift

    public func create(moduleId: String, context: TealiumContext, moduleConfiguration: DataObject) -> Module?

    Parameters

    moduleId

    The unique identifier for this specific module instance (ignored for BasicModuleFactory - only one module instance allowed)

    context

    The shared TealiumContext containing dependencies and configuration.

    moduleConfiguration

    The configuration data for this module.

    Return Value

    A new module instance if initialization succeeds, or nil if it fails.

  • Returns the enforced settings for this module.

    These settings will override any corresponding values from local or remote settings and remain constant throughout the module’s lifecycle.

    Declaration

    Swift

    public func getEnforcedSettings() -> [DataObject]

    Return Value

    An array containing the enforced settings DataObject, or an empty array if no enforced settings were provided during initialization.