0

I just upgraded to Swift 2.0 and am unsure as to why this line of code isn't working.I know toInt() was remove in Swift 2.0 but I can't figure how to update this line of code so it will work in Swift 2.0. Any suggestions?

Old line:

followers.setTitle((followers.currentTitle!.toInt()! - 1).description, forState: UIControlState.Normal)

I tried this line with no success:

followers.setTitle((followers.currentTitle!.Int()! + 1).description, forState: UIControlState.Normal)
vadian
  • 274,689
  • 30
  • 353
  • 361
  • It might be more efficient to declare an `Int` variable for the follower counter to do the math and update the title with `String(counter)`. – vadian Jan 28 '16 at 16:44

2 Answers2

3

Read the error message

toInt() is unavailable: Use Int() initializer

means

Int(followers.currentTitle!)!
vadian
  • 274,689
  • 30
  • 353
  • 361
  • Don't encourage them to implicitly unwrap things. Before you know it, they will post another question about it :p – Eendje Jan 28 '16 at 16:34
  • That is irrelevant for the question. `currentTitle` could be safely integer convertible. – vadian Jan 28 '16 at 16:38
1

Try this:

followers.setTitle((Int(followers.currentTitle!)! + 1).description, forState: UIControlState.Normal)
Matt Le Fleur
  • 2,708
  • 29
  • 40