-6

I try to call two arguments in following code:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let valueToPass = jobs[indexPath.row].text
    let passUserName = jobs[indexPath.row].addedByUser
    performSegue(withIdentifier: "toDetails", sender: valueToPass, passUserName)
}

But I get the error "Extra argument in call" How can I solve it??

EDIT: I tried following:

    let passItems = (valueToPass, passUserName)
     performSegue(withIdentifier: "toDetails", sender: [passItems])

But on the following VC the Labels are empty...

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SwiftTralla
  • 1
  • 1
  • 4
  • 1
    This is essentially a repost of [your previous question](https://stackoverflow.com/questions/53616890/expression-resolves-to-an-unused-property). What's wrong with the help you received there? – rmaddy Dec 08 '18 at 15:56
  • Because I try to pass the userLabel and the JobLabel separately and in my opinion my last question didn't described of what I try to solve, do you know what I mean? :/ – SwiftTralla Dec 08 '18 at 16:04
  • But the answer shows you what to do. Just pass a Job instance instead of individual fields from the Job instance. – rmaddy Dec 08 '18 at 16:06
  • @rmaddy I have to ask, is this really duplicate? – Robert Dresler Dec 08 '18 at 16:09
  • @RobertDresler I didn't close close it. But yes, this is since this question is the same as the previous but with the typo fixed. – rmaddy Dec 08 '18 at 16:10
  • @rmaddy yes I know, but I was interested about your opinion since you had wrote your comment "This is essentially a repost...". – Robert Dresler Dec 08 '18 at 16:12
  • Ok guys, I'm sorry for this, I'm completely new, but could you please help me with this? I've update my question with the new code according to your Answers but it is somehow still not working – SwiftTralla Dec 08 '18 at 16:23
  • Every time you fix one problem you face a new problem. Your latest issue is answered at https://stackoverflow.com/a/49818897/1226963 – rmaddy Dec 08 '18 at 16:28
  • BTW - don't completely redo your question after you have received answers. It negates all of the help you've received. – rmaddy Dec 08 '18 at 16:29
  • sorry but could you explain to me why adding a function which updates the view would be the only way to solve this? I didn't had nil errors like this before when I only passed the job.text – SwiftTralla Dec 08 '18 at 17:15

2 Answers2

1

Look, performSegue method is declare with these parameters:

withIdentifier identifier: String, sender: Any?

... so you can't add other parameters.

I suppose you have your custom data model

struct Job {
    var text: String
    var addedByUser: Bool
}

so for you would be the best, if you're passing the whole job as sender.

performSegue(withIdentifier: "toDetails", sender: jobs[indexPath.row])

then in prepare for segue method you can downcast sender as Job and set destination controller's job property

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "toDetails" {
        let destinationVC = segue.destionation as! JobDetailViewController
        destinationVC.job = sender as! Job
    }
}

so don't forget to replace text and addedByUser properties of JobDetailViewController by job

class JobDetailViewController: UIViewController {
    ...
    var job: Job?
    ...
}
Robert Dresler
  • 10,580
  • 2
  • 22
  • 40
0

Try this:

performSegue(withIdentifier: "toDetails", sender: indexPath)

Then, override this method:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {     
    if segue.identifier == "toDetails" {
        if let indexPath = sender as? IndexPath {
            if let nextVC = segue.destination as? DetailsViewController {
                let valueToPass = jobs[indexPath.row].text
                let passUserName = jobs[indexPath.row].addedByUser
                nextVC.text = valueToPass
                nextVC.userName = passUserName
            }
        }
    }
}

Note that you should have custom properties .text and .userName inside DestinationViewController.

ppalancica
  • 4,236
  • 4
  • 27
  • 42
  • I tried it but I get "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" as an Error - Yes I got the properties inside my DestinationVC – SwiftTralla Dec 08 '18 at 16:15
  • I've updated my Question and provided the Code from my DestinationVC – SwiftTralla Dec 08 '18 at 16:18