Reputation: 39
Let's say I have
struct cat {
var paws: int
var name: string
var breed: string
}
How would i go about segueing an instance to a new destination controller? Particularly, this instance from an array to a new DC?
prepare for segue
{
if segue.identifier == "segue"
var nextVC = segue.desitnationviewcontroller as ...
nextvc.instance = ?
}
Upvotes: 0
Views: 576
Reputation: 8883
You can just assign it like this:
let someCat = cat(paws: 4, name: "Kitty", breed: "Unknown")
let arrayCat = [cat(paws: 5, name: "Mutant", breed: "Unknown"),
cat(paws: 4, name: "John", breed: "Doe")]
var nextVC = segue.desitnationviewcontroller as SomeViewController
nextVC.somePropertyName = someCat // or arrayCat if you're using an array
In your SomeViewController
, you'll have to have a property with type cat
and you can just assign it. For example:
class SomeViewController: UIViewController {
var somePropertyName: cat? // [cat]() if it's an array of type cat
}
Also, for your convenience I added a link to Apple's documentation of Swift. The link is here.
Upvotes: 1