How to save entry to struct (swift4)

Right now my code prints the struct that was entered, but it can only print the last individual entry entered. It can only store 1 entry. How can I store and print every entry in the struct.

                 import UIKit

class ViewController: UIViewController {
@IBOutlet var c: UITextField!
@IBOutlet var a: UITextField!
@IBOutlet var b: UITextField!
var contacts: [Person] = []
override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

    @IBAction func press(_ sender: Any) {
        contacts.append(Person(name: a.text!, surname: b.text!  , phone: Int(c.text!)!))

    struct Person {
        var name: String
        var surname: String
        var phone: Int


@timswift You’re storing all the items in the contacts array, so simply loop through it if you want to print them all out.

for var contact in contacts {

This topic was automatically closed after 166 days. New replies are no longer allowed.