Skip to content

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.

2 participants