Convert string to integer

 Problem

I have a string and want to parse its integer value (if any).



 Recipe


// String literal
let s = "1986"

// Get Integer value from string
var n = Int(s)

// It's an Optional Int -
// in case the conversion goes wrong
print(n!)


				


 Playground