         }
     }
 
+    private var didSetInitialPlaceholderText: Bool {
+        get { return associatedObject(&AssociatedKey.didSetInitialPlaceholderText, default: false) }
+        set { setAssociatedObject(&AssociatedKey.didSetInitialPlaceholderText, value: newValue) }
+    }
+
+    private var initialPlaceholderText: String? {
+        get { return associatedObject(&AssociatedKey.initialPlaceholderText) }
+        set { setAssociatedObject(&AssociatedKey.initialPlaceholderText, value: newValue) }
+    }
+
     @objc private var swizzled_placeholder: String? {
         get { return textField?.attributedPlaceholder?.string }
         set {
+            if superview == nil, let newValue = newValue {
+                initialPlaceholderText = newValue
+                return
+            }
+
             guard let textField = textField else {
                 return
             }

                textField.attributedPlaceholder = NSAttributedString(string: newValue)
            }
        }
    }
}


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.
