Skip to content

Instantly share code, notes, and snippets.

View hsleedevelop's full-sized avatar
🔥

HS Lee hsleedevelop

🔥
View GitHub Profile
@hsleedevelop
hsleedevelop / getIPAddressFromHotspot.swift
Created May 11, 2017 13:50
get IPAddress From Hotspot
//#include <ifaddrs.h> in bridging-header first.
fileprivate func getIPAddress() -> String? {
var address : [String]? = []
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return nil}
guard let firstAddr = ifaddr else { return nil}
//http://stackoverflow.com/questions/41940994/closure-cannot-implicitly-capture-a-mutating-self-paramter/41941810#41941810
private func capture(with block: @escaping () -> ()) { block() }
let sdevices = devices.flatMap({ (device: Device) -> String in
return "\(device.brand)-\(device.hostname)-\(device.ipAddress)-\(device.macAddress)\n"
}).flatMap({$0}).joined()
DispatchQueue.main.async {
JDAlert(title: "Found \(devices.count) Device(s).", message: sdevices, preferredStyle: .alert)
.addAction(title: "OK", style: .default) { _ in }
.show()
}