Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty placeholder crash, and remove deprecated method from iOS 13 #202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

benck
Copy link

@benck benck commented Aug 15, 2021

When the placeholder for the textfield is set to an empty string (textField.placeholder = ""). In the buildPlaceholderLabel() method, using attribute(.foregroundColor, at: 0, effectiveRange: nil) for an empty string will cause crash.

            if let placeholderColor = self.attributedPlaceholder?.attribute(NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: nil) as? UIColor {
                placeholderLabel?.textColor = placeholderColor
            }

So I add the code to check if the attributedPlaceholder is empty before calling attribute() method.

            if let attributedPlaceholder = self.attributedPlaceholder, attributedPlaceholder.length > 0,
               let placeholderColor = attributedPlaceholder.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? UIColor {
                placeholderLabel?.textColor = placeholderColor
            }

This branch also merge @pateldhruvil96 's fix for Swift Package Manager support, and remove deprecated method from iOS 13.

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

Successfully merging this pull request may close these issues.

None yet

2 participants