To create an instance of a class with a constructor in Swift, you need to follow these steps:
main.swift145 chars10 lines
main.swift43 chars2 lines
Here, we create a new instance of the Person class using the constructor that takes two parameters - name and age.
main.swift50 chars2 lines
This will print out:
main.swift20 chars2 lines
Here, we access the name and age properties of the person instance using dot notation.
That's it! You have now created an instance of a class with a constructor in Swift.
gistlibby LogSnag