How to remove [] from print struct

My Code below prints a struct its how I want it expect for the []. I just want it removed.

          var contacts = [Person]()

    @IBAction func press(_ sender: Any) {
        contacts.append(Person(name: a.text!,  phone: Int(c.text!)!))
        label.text = self.contacts.description
    }}
struct Person {
var name: String
var phone: Int}

  extension Person: CustomStringConvertible {
var description: String {
    return "\n\(name),\(phone)"
}}

Hi @timswift

You are accessing “description” property of the array, not the Person class instance.
You need to loop through array:

for person in contacts
{
   print(person.description)
}

Hope this is helpful

Thanks

What function should i put it in the action button?

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