FactoryInitializable

public protocol FactoryInitializable : Sendable

Classes whose initializers actually create derived classes

  • The type of the least-derived class declared to be FactoryInitializable.

    Warning

    Do not define this in your FactoryInitializable type!

    Declaration

    Swift

    associatedtype FactoryBase : AnyObject, FactoryInitializable = Self

Available where Self: AnyObject

  • init(unsafelyAliasing:) Extension method

    Optimally “creates” an instance that is just another reference to me.

    Requires

    me is Self.

    Taking FactoryBase as a parameter prevents, at compile-time, the category of bugs where me is not derived from the least-derived ancestor of Self conforming to FactoryInitializable.

    However, there are still ways me might not be derived from Self. If you have factory initializers at more than one level of your class hierarchy and you can’t control exactly what is passed here, use init(aliasing:) instead.

    Declaration

    Swift

    public init(unsafelyAliasing me: FactoryBase)
  • init(aliasing:) Extension method

    Safely “creates” an instance that is just another reference to me.

    Requires

    me is Self.

    Declaration

    Swift

    public init(aliasing me: FactoryBase)