How to convert int to nsindexpath?

Adam Young picture Adam Young · Apr 3, 2015 · Viewed 29.7k times · Source

I am making a basic quiz application.The choices are in the form of a table view. If the user moves to a previous question, I want to show him his previously selected choice. I have stored the choice in NSUserDefaults. How do I convert this int value to NSIndexpath and use it in my tableview?

Answer

zisoft picture zisoft · Apr 3, 2015

See the NSINdexPath UIKit Additions

In your case you can use (Swift):

let indexPath = NSIndexPath(forRow: 0, inSection: 0)

Swift 3.0:

let indexPath = IndexPath(row: 0, section: 0)