0

I have a class that allows the user to enter a website name, their account, and password. So this class holds three variables.

The user is going to use this class several times so I want to make an array that holds the information for each time they use the class. I am a beginner student programmer and need help in doing this. If anyone can guide me that would be appreciated!

1 Answers1

0

you can do it like this:

class User
{
    var websiteName: String
    var account: String
    var password: String
    init(websiteName: String, account: String, password: password)
    {
        self. websiteName = websiteName
        self. account = account
        self. password = password
    }
}

And Then for using it on your code:

var users: [User] = []
var maria = User(websiteName: "http://www.stackoverflow.com", account: "User Account", password: "User Password")
users.append(maria)

Array initialization is var users: [User] and as an example I have appended one user for you to see how its done.

Mago Nicolas Palacios
  • 2,501
  • 1
  • 15
  • 27