Get Broadcast address in swift

#include 

Add above line in your bridging header

func getBroadcastAddress(ipAddress: String, subnetMask: String) -> String {
        let ipAdressArray = ipAddress.split(separator: ".")
        let subnetMaskArray = subnetMask.split(separator: ".")
        guard ipAdressArray.count == 4 && subnetMaskArray.count == 4 else {
            return "255.255.255.255"
        }
        var broadcastAddressArray = [String]()
        for i in 0..<4 {
            let ipAddressByte = UInt8(ipAdressArray[i]) ?? 0
            let subnetMaskbyte = UInt8(subnetMaskArray[i]) ?? 0
            let broadcastAddressByte = ipAddressByte | ~subnetMaskbyte
            broadcastAddressArray.append(String(broadcastAddressByte))
        }
        return broadcastAddressArray.joined(separator: ".")
    }

Get Current wifi IP address and subnet mask

func getIFAddresses() -> [NetInfo] {
        var addresses = [NetInfo]()
        
        // Get list of all interfaces on the local machine:
        var ifaddr : UnsafeMutablePointer? = nil
        if getifaddrs(&ifaddr) == 0 {
            
            var ptr = ifaddr;
            while ptr != nil {
                
                let flags = Int32((ptr?.pointee.ifa_flags)!)
                var addr = ptr?.pointee.ifa_addr.pointee
                let interface = ptr?.pointee
                // Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
                if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
                    if addr?.sa_family == UInt8(AF_INET) || addr?.sa_family == UInt8(AF_INET6) {
                        
                        if let name: String = String(cString: (interface?.ifa_name)!), name == "en0" {
                            
                            // Convert interface address to a human readable string:
                            var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                            if (getnameinfo(&addr!, socklen_t((addr?.sa_len)!), &hostname, socklen_t(hostname.count),
                                            nil, socklen_t(0), NI_NUMERICHOST) == 0) {
                                if let address = String.init(validatingUTF8:hostname) {
                                    
                                    var net = ptr?.pointee.ifa_netmask.pointee
                                    var netmaskName = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                                    getnameinfo(&net!, socklen_t((net?.sa_len)!), &netmaskName, socklen_t(netmaskName.count),
                                                nil, socklen_t(0), NI_NUMERICHOST)// == 0
                                    if let netmask = String.init(validatingUTF8:netmaskName) {
                                        addresses.append(NetInfo(ip: address, netmask: netmask))
                                    }
                                }
                            }
                        }
                        
                    }
                }
                ptr = ptr?.pointee.ifa_next
            }
            freeifaddrs(ifaddr)
        }
        return addresses
    }
struct NetInfo {
    let ip: String
    let netmask: String
}

Final call methods

let ip = getIFAddresses().last!.ip
let netmask = getIFAddresses().last!.netmask
print(ip)
print(netmask)
print(getBroadcastAddress(ipAddress: ip, subnetMask: netmask))