Skip to content

Instantly share code, notes, and snippets.

View korvit's full-sized avatar

Vitaly Korobchuk korvit

  • University of Padua
  • Padua,Italy
View GitHub Profile
struct TreadSafeDict<Key:Hashable, Element> {
let queue = DispatchQueue(label: "thread-safe-queue")
typealias DictionaryType = [Key : Element]
private var _elements = DictionaryType()
init(elements: DictionaryType) {
queue.sync {
// Return IP address of WiFi interface (en0) as a String, or `nil`
func getWiFiAddress() -> 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 }
// For each interface ...