Chapter 16 Protocols

Screenshot 2020-05-17 at 15.58.43

Could somebody please explain the following line:
var accountType: Account.Type = BitcoinAccount.self

In the book it is not explained.
Account.Type
BitcoinAccount.self

Thanks!

Hi @noah8610, the variable accountType is adopting the instance of the Account protocol. By using the colon with var accountType we are declaring the type to be the protocol Account. After declaring the type we are assigning the variable to BitcoinAccount.self which is then an expression of the BitcoinAccount class. By having accountType, we can then use it to set an initial amount and transfer amount with the account & transferAccount constants. Both constants are accessing the variable accountType.

Best,
Gina

1 Like

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