call a public property on an instance of a class in swift

To call a public property on an instance of a class in Swift, you can use dot notation.

Assuming you have a class Person with a public property name, you could create an instance of the Person class and call the name property like this:

main.swift
// Define the Person class
class Person {
  public var name: String
  
  init(name: String) {
    self.name = name
  }
}

// Create an instance of the Person class
let john = Person(name: "John")

// Call the name property using dot notation
print(john.name) // Output: "John"
277 chars
15 lines

gistlibby LogSnag