0

I am new in swift I am trying to send some information on click on cell of Table view using segue,but when i try to compile i get this error.. I am using Xcode 6.1 and SDK 8.1

      override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?) {

    if segue.identifier == "update"{           

       let selectedItems : NSManagedObject = arr[self.tableView.indexPathForSelectedRow().row] as NSManagedObject


    let IVC : ViewController = segue.destinationViewController as ViewController
        IVC.itemVar = selectedItems.valueForKey("item") as String
        IVC.qtyVar = selectedItems.valueForKey("qty") as String
        IVC.discVar = selectedItems.valueForKey("disc") as String
        IVC.selectedItem = selectedItemse

    }

}

1 Answers1

0

You have to unwrap the returned indexPath

self.tableView.indexPathForSelectedRow()!.row

but do this only if you are sure, returned indexPath will always have value(it wont be nil)

Othrewise make the unwrapping this way:

if let indexPath = self.tableView.indexPathForSelectedRow(){
    indexPath.row
}
IxPaka
  • 1,990
  • 1
  • 16
  • 18
  • IxPaka : Thanks its working,you have save my lot of time ,i have been searching this from last 2 hours, and i have one issue with optionals ? and ! can u plz explain it..where should i use ? and ! – Yogesh Jadhav Mar 13 '15 at 08:51
  • @YogeshJadhav well, ? should be used where you are not sure whether you will always have a value to work with, otherwise you can use !. Here is a related topic with much more clear explenation about it http://stackoverflow.com/questions/24018327/what-does-an-exclamation-mark-mean-in-the-swift-language – IxPaka Mar 13 '15 at 09:01
  • IxPaka : Thanks,I am new in swift I am from Java,now I am working with CoreData Framework and I am also searching which way is best for doing transaction. There is lot of way I found on google,but I don't know which way should I go with. or in real app development which way should use to store data into database? – Yogesh Jadhav Mar 13 '15 at 10:11
  • @YogeshJadhav for storing data you can check out FMDB framework, which is a wrapper for SQLite for iOS or Core Data from Apple and you can checkout NSUserDefaults where you can store some values too, but it shoud not be used to store large amount of data, just some small amount of info, for example if this is apps first launch etc. – IxPaka Mar 13 '15 at 10:18