To add a public method to a class in Swift, you simply need to prefix the method declaration with the public
keyword. Here's an example:
main.swift108 chars6 lines
In the example above, MyClass
is a public class and myPublicMethod()
is a public method. This means that the method can be accessed from outside the class, by other classes or modules that import this one.
If you don't add the public
keyword to your method, it will be treated as an internal method, which means it can only be accessed from within the same module.
gistlibby LogSnag