0

Trying to turn a record ID into an Int32 and ending up with a verbose three line/layer trick to achieve the obvious. There must be a shorter way. Can someone put me out of my misery?

var XX = resultSet.stringForColumn("ID")
var XXX = XX.toInt()
recordNumberBack = Int32(XXX!)
Edward Hasted
  • 3,201
  • 8
  • 30
  • 48
  • SQLite does many conversions automatically, so what happens if you just call `recordNumberBack = resultSet.intForColumn("ID")` ? – Martin R Jun 14 '15 at 19:17
  • That's assigning a string to an Int32 which it doesn't like. I can put it all in one line like recordNumberBack = Int32(resultSet.stringForColumn("ID").toInt()!) but is there a more compact way? – Edward Hasted Jun 15 '15 at 04:38
  • `intForColumn()` returns an `int` which corresponds to `Int32` in Swift, so assigning that to `recordNumberBack` should work. It should use SQLites internal casting from strings to integers. – Martin R Jun 15 '15 at 04:43
  • That is what I would have thought too. – Edward Hasted Jun 17 '15 at 09:03

0 Answers0