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.
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.
So I add the code to check if the attributedPlaceholder is empty before calling attribute() method.
This branch also merge @pateldhruvil96 's fix for Swift Package Manager support, and remove deprecated method from iOS 13.