add a public property to a class in swift

To add a public property to a class in Swift, simply declare the property within the class with the public access modifier. For example:

main.swift
public class MyClass {
    public var myProperty: String

    public init(myProperty: String) {
        self.myProperty = myProperty
    }
}
141 chars
8 lines

In the example above, the myProperty property is defined as public and can be accessed and modified from outside the class.

gistlibby LogSnag