The Problem:
I have a large project that has UILabel, TextFields, etc.. that are not currently being set with a placeholder in the event that data is missing. I currently have a constants file with Constants.placeholder
which returns "-
". I need a way to reliably set that value on any UILabel
that is contained in the UIView
.
Possible Solutions:
I could create a function that accepts UIView
then iterates over the subViews replacing any instance of UILabel's text value with Constants.placeholder
the problem with this solution is that I have some labels that are static, set in interface builder, of which I DON'T want to change those. Similar to this: Swift: Get all subviews of a specific type and add to an array
Another thought I had was to create a function that accepts an array of [UILabel]
and iterate over those, which could be done and is valid, however it may take quite a bit of work to implement that.
func reset(labels: [UILabel]) {
for label in labels {
label.text = Constants.placeholder
}
}
My final thought was to somehow intercept awakeFromNib
and force set the references, but I don't think this is technically feasible. Ultimately I need to set that value, Constants.placeholder
, anywhere I have a UILabel that is being set, without having to manually do it everywhere.