When creating SkyFloatingLabelTextField from storyboard and overriding certain properties, it is possible to get an Unexpectedly found nil while unwrapping an Optional value fatal error in updateLineColor() and some other methods.
Here is a minimal working example:
import SkyFloatingLabelTextField
import UIKit
final class ViewController: UIViewController {
@IBOutlet private weak var textField: SkyFloatingLabelTextField!
}
extension SkyFloatingLabelTextField {
override open var isSecureTextEntry: Bool {
didSet {
textColor = isSecureTextEntry ? .blue : .red
}
}
}
The proposed pull request solves this issue by performing optional unwrapping with guards.
I didn’t check all places where implicit option unwrapping occurs, so there may be other crashes left related to this issue. To properly address it I was thinking to rewrite the component to have pairs of optional and non-optional properties (e.g., optional customLineView and non-optional lineView). That way user will still be able to customize the respective views and there will be a reliable fallback option. It is out of scope of this pull request, but if you deem it useful I can explore it further and prepare a separate proposal.
When creating
SkyFloatingLabelTextField
from storyboard and overriding certain properties, it is possible to get anUnexpectedly found nil while unwrapping an Optional value
fatal error inupdateLineColor()
and some other methods.Here is a minimal working example:
(Full Xcode project.)
The proposed pull request solves this issue by performing optional unwrapping with
guard
s.I didn’t check all places where implicit option unwrapping occurs, so there may be other crashes left related to this issue. To properly address it I was thinking to rewrite the component to have pairs of optional and non-optional properties (e.g., optional
customLineView
and non-optionallineView
). That way user will still be able to customize the respective views and there will be a reliable fallback option. It is out of scope of this pull request, but if you deem it useful I can explore it further and prepare a separate proposal.