thomiceli revised this gist 5 hours ago. Go to revision
1 file changed, 23 insertions
aaa.swift(file created)
| @@ -0,0 +1,23 @@ | |||
| 1 | + | class BankAccount { | |
| 2 | + | var balance: Int | |
| 3 | + | ||
| 4 | + | // Initializer to set the initial state of the object | |
| 5 | + | init(balance: Int) { | |
| 6 | + | self.balance = balance | |
| 7 | + | self.cpuCard = "gg" | |
| 8 | + | } | |
| 9 | + | ||
| 10 | + | // Method to modify the balance | |
| 11 | + | func deposit(_ amount: Int) { | |
| 12 | + | balance += amount | |
| 13 | + | } | |
| 14 | + | } | |
| 15 | + | ||
| 16 | + | // Create an instance (object) of the BankAccount class | |
| 17 | + | let account = BankAccount(balance: 100) | |
| 18 | + | ||
| 19 | + | // Call a method to interact with the object | |
| 20 | + | account.deposit(25) | |
| 21 | + | ||
| 22 | + | // Access a property using dot syntax | |
| 23 | + | print(account.balance) // Prints "125" | |
Newer
Older