How are global functions defined in Swift? How are global functions defined in Swift? swift swift

How are global functions defined in Swift?


Unless you declare the function as private or fileprivate, which limit the visibility to the file or scope where it is defined, you can use it anywhere in the module if declared as internal (the default), and also from external modules if declared as public or open.

However since you say that you need it in view controllers only, why not implementing it as an extension to the view controller?

extension UIViewController {    func displayAlert(title:String, error:String, buttonText: String) {        ...    }}