title: How to convert RGB values to HEX string iOS swift
body: <p>I Want to convert RGB values to Hex string. I convert Hex to RGB as follow but how I do vice versa.</p>
  
  <pre><code>func hexStringToRGB(_ hexString: String) -&gt; (red: CGFloat, green: CGFloat, blue: CGFloat) {
      var cString:String = hexString.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
  
      if (cString.hasPrefix("#")) {
          cString.remove(at: cString.startIndex)
      }
  
      if ((cString.count) != 6) {
          return (red: 0.0, green: 0.0, blue: 0.0)
      }
  
      var rgbValue:UInt32 = 0
      Scanner(string: cString).scanHexInt32(&amp;rgbValue)
  
      return (
          red: CGFloat((rgbValue &amp; 0xFF0000) &gt;&gt; 16),
          green: CGFloat((rgbValue &amp; 0x00FF00) &gt;&gt; 8),
          blue: CGFloat(rgbValue &amp; 0x0000FF))
  }
  </code></pre>