|
@@ -70,29 +70,33 @@ class NetworkMonitor: NSObject {
|
|
|
var networks = self.savedNetworks
|
|
|
|
|
|
for nw in receivedNetworks {
|
|
|
- let index = findNetworkWithID(nw.nwid)
|
|
|
+ let index = findSavedNetworkWithID(nw.nwid)
|
|
|
|
|
|
if index != NSNotFound {
|
|
|
networks[index] = nw
|
|
|
}
|
|
|
- networks.sortInPlace({ (left, right) -> Bool in
|
|
|
- if left.nwid < right.nwid {
|
|
|
- return true
|
|
|
- }
|
|
|
+ else {
|
|
|
+ networks.append(nw)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ networks.sortInPlace({ (left, right) -> Bool in
|
|
|
+ if left.nwid < right.nwid {
|
|
|
+ return true
|
|
|
+ }
|
|
|
|
|
|
- return false
|
|
|
- })
|
|
|
+ return false
|
|
|
+ })
|
|
|
|
|
|
- objc_sync_enter(allNetworks)
|
|
|
- allNetworks = networks
|
|
|
- objc_sync_exit(allNetworks)
|
|
|
+ objc_sync_enter(allNetworks)
|
|
|
+ allNetworks = networks
|
|
|
+ objc_sync_exit(allNetworks)
|
|
|
|
|
|
- saveNetworks()
|
|
|
+ saveNetworks()
|
|
|
|
|
|
- let nc = NSNotificationCenter.defaultCenter()
|
|
|
+ let nc = NSNotificationCenter.defaultCenter()
|
|
|
|
|
|
- nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
|
|
|
- }
|
|
|
+ nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
|
|
|
}
|
|
|
|
|
|
private func findNetworkWithID(nwid: UInt64) -> Int {
|
|
@@ -106,6 +110,17 @@ class NetworkMonitor: NSObject {
|
|
|
return NSNotFound
|
|
|
}
|
|
|
|
|
|
+ private func findSavedNetworkWithID(nwid: UInt64) -> Int {
|
|
|
+ for (index, element) in savedNetworks.enumerate() {
|
|
|
+
|
|
|
+ if element.nwid == nwid {
|
|
|
+ return index
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return NSNotFound
|
|
|
+ }
|
|
|
+
|
|
|
private func saveNetworks() {
|
|
|
let file = dataFile()
|
|
|
|