How to set status bar background color in swift

func setStatusBarBackgroundColor(color: UIColor) {
      guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
      statusBar.backgroundColor = color
}