I have a class of User that has a lot of user data in it. Like a contact app, I would like when someone taps on the contact it loads a contact card. Usually I use prepareForSegue and a storyboard segue to pass values of String, Int, Array, etc but I can't seem to figure out how to send a value of type User. On the sending side, I've set it up correctly but I can't figure out how to set up the receiving view. The reason why I want to send the whole thing instead of using dot syntax and grabbing each element individually is because (like the contacts app) I want the user to be able to add fields to the contact card and I don't want to have to type out all of the data that I need to pass unless I have to.
User class:
class User {
var firstName = ""
var lastName = ""
var email = ""
var birthday = ""
var team = ""
var schedule = ""
var service = ""
var position = ""
var phoneNumber = ""
var dateStarted = ""
var profileImgURL = ""
var notes = ""
init (firstName:String, lastName:String, email:String, birthday:String, team:String, schedule:String, service:String, position:String, phoneNumber:String, dateStarted:String, profileImgURL:String, notes:String) {
self.firstName = firstName
self.lastName = lastName
self.email = email
self.birthday = birthday
self.team = team
self.schedule = schedule
self.service = service
self.position = position
self.phoneNumber = phoneNumber
self.dateStarted = dateStarted
self.profileImgURL = profileImgURL
self.notes = notes
}
Sender:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "SeeContactCardSegue" {
if let destVC = segue.destinationViewController as? ContactCardTVC {
if let indexPath = tableView.indexPathForSelectedRow {
let user = users[indexPath.row]
destVC.user = user
}
}
}
}
Receiver:
var user:User = ???
I get an error saying user needs to be initialized, which I get in most situations but I am not sure how to initialize this. Am I missing something?