I just noticed that one of the many changes in Swift 3 also concerns KM variables in Swift script macros.
In Swift 3 you can access KM variables with
ProcessInfo.processInfo.environment["KMVAR_<variableName>"]!
For example:
import Foundation
print(ProcessInfo.processInfo.environment["KMVAR_myKMVariable"]!)
For reference, this is what works with Swift 2.x:
import Foundation
print(NSProcessInfo.processInfo().environment["KMVAR_myKMVariable"]!)