Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Make the designated initializers with a viewClass argument public #254

@hooliooo

Description

@hooliooo

Hi there,

Is there any reason why the initializers, containing the viewClass argument, are marked internal? It would be extremely useful if they were exposed as public.

Reason:
Let's say for example you want to define a SizeLayout and you want to determine what UITextField.Type you want to use at runtime, the current public initializers for SizeLayout prevents you from doing so.

func createSizeLayout<T: UITextField>(type: T.Type) -> SizeLayout<T> {
    .... logic for creation here ...
}

let textFieldLayout = createSizeLayout(type: YourCustomTextField.self) // this inferred as SizeLayout<UITextField> 

// if you follow the initialization steps, the used initializer in BaseLayout is:
public init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, config: ((V) -> Void)?) {
    self.alignment = alignment
    self.flexibility = flexibility
    self.viewReuseId = viewReuseId
    self.viewClass = V.self
    self.config = config
}

// instead of:
init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, viewClass: V.Type, config: ((V) -> Void)?) {
    self.alignment = alignment
    self.flexibility = flexibility
    self.viewReuseId = viewReuseId
    self.viewClass = viewClass
    self.config = config
}

Using the latter will still yield an inferred type of SizeLayout<UITextField> BUT if you set breakpoints in the config closure it will be a YourCustomTextField instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions