-3

How to convert from this code to swift can you please help me

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender   {
    if ([segue.identifier isEqualToString:@"showDetail"]) {
       NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
       viewController *viewController = segue.destinationViewController;
        viewController.name = [Array objectAtIndex:indexPath.row];
    }
}
  • Did you even try to google? http://stackoverflow.com/questions/24040692/prepare-for-segue-in-swift – Woodstock Apr 08 '15 at 14:27
  • @gireesh Chanti I put an answer for your question, but you need to know that stackoverflow isn't for translate from one language to another exactly. I hope you understand, you have to show effort in your research!!! – Victor Sigler Apr 08 '15 at 14:33
  • I Got Solution for this.[link](https://objectivec2swift.com/#/home/converter/) using this link we can convert any code from objective c to Swift. – gireesh Chanti Apr 27 '17 at 09:57

1 Answers1

2

Try this:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showRecipeDetail" {
        var indexPath = self.tableView.indexPathForSelectedRow()
        var destViewController = segue.destinationViewController as! RecipeDetailViewController            
        destViewController.recipe = recipes[indexPath.row]
    }
}
Victor Sigler
  • 22,807
  • 14
  • 85
  • 100
  • but its not working.can you please give me any suggestions for passing values from one view controller to two or more view controllers using prepareForSegue...Thank you – gireesh Chanti Apr 08 '15 at 14:38
  • It's the way is you have a `segue` to another `ViewController`, just in the `prepareForSegue` function. I just translate your code , I don't have a way to test it for sure. Tell me if you have any errors? – Victor Sigler Apr 08 '15 at 14:41
  • It's not pass from table to another view controller.Actually i have 5 rows ,each one have separate view controller.If i click one row it will go to the familiar view controller. Can you please suggest how to do......Thank you – gireesh Chanti Apr 08 '15 at 14:55
  • You have to define your custom cells first, and for each define a `segue` for the **ViewController's** you want, or in other way , you can define one prototype cell for everyone and in the `didSelectRowAtIndexPath` present the `ViewController` you want in base the number of the row tapped, I prefer the first way, you can do it using Interface Builder directly. – Victor Sigler Apr 08 '15 at 14:59
  • It's nice ,In first way i did,but i want to know how to do through programatically thank you @Victor Sigler – gireesh Chanti Apr 08 '15 at 15:09