title: Display base64 encoded image in imageview: SWIFT 3
body: <p>I have base64 image string which is downloaded from a webpage using POST request and I am trying to decode and display inside imageview but it's not working. I have tried couple of sources but no luck :(</p>
  
  <pre><code>let base64String = "data:image/jpg;base64,/9j/4aaQSkZJRg0BMADAE15a5df.....H/12Q=="
  </code></pre>
  
  <p>Currently, trying this method:</p>
  
  <pre><code>if let decodedData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacter) {
     let image = UIImage(data: decodedData)
     ImageView.image = image
  } else {
          print("error in decoding")
    }
  </code></pre>
  
  <p>Tried <code>NSData</code> method also:</p>
  
  <pre><code>let dataDecode:NSData = NSData(base64Encoded: base64String!, options:.ignoreUnknownCharacters)!
  let image= UIImage(data: dataDecode as Data)!
  yourImageView.image = image
  </code></pre>
  
  <p>The <code>else</code> part always executes. I have tried this in xCode playground by putting encoded string in static variable and noticed <code>nil</code> in front of if condition line.</p>
  
  <p>Not sure, what I am doing wrong?</p>