Abhijit Patil
Abhijit Patil

Reputation: 19

how to send json array to different view controller in swift using segue

i want to send the json array from one view controller to another view controller and the array should be populated in pickerview . but i am unable to send the array . i am getting the array but not able to send it

let mydata = json["data"] as! NSArray    
                                print("My Data is \(mydata)")
                                var sendData = [NSArray]()
                                sendData = mydata as! Array<NSArray>
                                self.performSegue(withIdentifier: "checkLoginViewController", sender: sendData)

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            if let destinationVC = segue.destination as? SignupViewController, let sendData = sender as? [String]{    
                destinationVC.dept = sendData    
            }    
        }

secondVC:

var dept = [String]()

Upvotes: 0

Views: 233

Answers (2)

Yogesh Makwana
Yogesh Makwana

Reputation: 448

   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let destinationVC = segue.destination as? SignupViewController, let sendData = sender as? {    
            destinationVC.dept = sendData    
        }    
    }

try this code

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100541

The problem is that you use Array<NSArray>

  endData = mydata as! Array<NSArray>

and in prepare cast it like

   let sendData = sender as? [String]

which for sure cast will fail

Upvotes: 2

Related Questions