Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Conversation

@alextov

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
        }
    }

}

(Full Xcode project.)

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.

@k0nserv
Copy link
Contributor

Thanks Oleksandr Tovstonozhenko (@alextov) this looks good, can you add a line to CHANGELOG.md crediting yourself too?

@alextov

Hugo Tunius (@k0nserv) Done.

@k0nserv Hugo Tunius (k0nserv) merged commit d492acb into Skyscanner:master Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants