Define a class Behaviour as Methods in Swift

Class Account defines two public methods for manipulating the balance.

i. Method deposit ensures that the deposit amount is positive and if so, add the amount to the balance.

ii. Method withdrawal ensures that the withdrawal amount is positive and that subtracting that amount from the balance will not overdraw the account, and if so, subtracts the amount from the balance.

Example-1:

public func deposit(amount: Double)
{
if amount > 0.0 {
balance = balance + amount
}
}

Example-2:


public func withdraw(amount: Double)
{
if amount > 0.0 {
if balance - amount >= 0.0{
balance = balance - amount
}
}
}