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
Moduletype must conform toBasicModule - Modules created by this factory cannot be instantiated multiple times (
allowsMultipleInstancesis alwaysfalse) - Use
ModuleSettingsBuildersubclasses for type-safe configuration - Module type constants should be defined in
Modules.Typesfor consistency
-
The unique identifier for the type of module this factory creates.
Declaration
Swift
public let moduleType: String -
Always
falsefor 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
moduleTypeA unique string identifier for the module type. This should match the module type used in settings and configuration.
enforcedSettingsOptional 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
nilif initialization fails due to invalid or insufficient configuration.Declaration
Swift
public func create(moduleId: String, context: TealiumContext, moduleConfiguration: DataObject) -> Module?Parameters
moduleIdThe unique identifier for this specific module instance (ignored for BasicModuleFactory - only one module instance allowed)
contextThe shared TealiumContext containing dependencies and configuration.
moduleConfigurationThe configuration data for this module.
Return Value
A new module instance if initialization succeeds, or
nilif 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.
View on GitHub