0

I need to pass a structure reference from one view controller to another. Here is my code's part:

//In CollectionViewController.swift

 struct ViewCell{
    var lbl : String
    var details: String
 }
 var cellDetails = [ViewCell]()
 //In a action method of button tapped
 let vc = CollectionViewController2.init(nibName: 
           "CollectionViewController2", bundle: nil)
 vc.cellDetails2 = self.cellDetails
 self.navigationController?.pushViewController(vc, animated: true)
 //In CollectionViewController2.swift ---**                
struct ViewCell2{
    var lbl : String
    var details: String
}
var cellDetails2 = [ViewCell2]()

code shows me error:

"Cannot assign value of type '[CollectionViewController.ViewCell]' to type '[CollectionViewController2.ViewCell2]'".

But why? How can I resolve it?

  • Show the definitions of `cellDetails` and `CellDetails`. It sounds as if they are separate types, local to the controllers. (Note: types should start with a capital letter and variables with lower case so that they're easily identified.) – Phillip Mills Dec 27 '19 at 15:03
  • Define `ViewCell` once, outside any controller and then share the definition in both places as `[ViewCell]`. – Phillip Mills Dec 30 '19 at 14:04

0 Answers0