                 textField.attributedPlaceholder = NSAttributedString(string: newValue)
             }
         }
+    }
+
+    open override func didMoveToSuperview() {
+        super.didMoveToSuperview()
+        guard superview != nil, !didSetInitialPlaceholderText else { return }
+
+        if let placeholderText = initialPlaceholderText {
+            placeholder = placeholderText
+            initialPlaceholderText = nil
+        }
+
+        didSetInitialPlaceholderText = true
     }
 }
 

        }
    }

    @objc private var swizzled_placeholder: String? {
        get { return textField?.attributedPlaceholder?.string }
        set {
            guard let textField = textField else {
                return
            }

extension UISearchBar {
    private struct AssociatedKey {
        static var placeholderTextColor = "placeholderTextColor"
        static var initialPlaceholderText = "initialPlaceholderText"
        static var didSetInitialPlaceholderText = "didSetInitialPlaceholderText"
    }

    /// The default value is `nil`. Uses `UISearchBar` default gray color.
