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

Make the designated initializers with a viewClass argument public #254

Open
hooliooo opened this issue Apr 11, 2019 · 0 comments
Open

Make the designated initializers with a viewClass argument public #254

hooliooo opened this issue Apr 11, 2019 · 0 comments

Comments

@hooliooo
Copy link

hooliooo commented Apr 11, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant