Unistd pause()

If I want to create a top level func called pause, it seems this is not possible with Swift 6.
Or at least, compiling with swiftc gives this error:

error: ambiguous use of 'pause()'

The reason being that unistd already has a function by that name.
Is there a compiler flag to ignore symbols from libc?

Symbols from libc are only visible in Swift if you've imported your platform's libc module (directly or indirectly.)

You can specify the module name to disambiguate the two functions. For instance, if your module is named MyPackage:

MyPackage.pause()
1 Like

Also you can use enum as namespace.

enum MyNameSpace {
    static func pause() {
        print("Press Enter to continue...")
        readLine()
    }
}

MyNameSpace.pause()