How to get available wifi network name in iOS using swift

iOS 12

You must enable Access WiFi Information from capabilities.

Important To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. Documentation link

First;

import SystemConfiguration.CaptiveNetwork

Then;

 func getInterfaces() -> Bool {
    guard let unwrappedCFArrayInterfaces = CNCopySupportedInterfaces() else {
        print("this must be a simulator, no interfaces found")
        return false
    }
    guard let swiftInterfaces = (unwrappedCFArrayInterfaces as NSArray) as? [String] else {
        print("System error: did not come back as array of Strings")
        return false
    }
    for interface in swiftInterfaces {
        print("Looking up SSID info for \(interface)") // en0
        guard let unwrappedCFDictionaryForInterface = CNCopyCurrentNetworkInfo(interface) else {
            print("System error: \(interface) has no information")
            return false
        }
        guard let SSIDDict = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else {
            print("System error: interface information is not a string-keyed dictionary")
            return false
        }
        for d in SSIDDict.keys {
            print("\(d): \(SSIDDict[d]!)")
        }
    }
    return true
}