Browse Source

Work around for several strange corner cases in Automatic Reference Counting in Apple's runtime

Grant Limberg 9 years ago
parent
commit
ba0a45365c

+ 1 - 1
ZeroTier One/LaunchAtLoginController.m

@@ -69,7 +69,7 @@ void sharedFileListDidChange(LSSharedFileListRef inList, void *context)
     if (wantedURL == NULL || fileList == NULL)
         return NULL;
 
-    NSArray *listSnapshot = (__bridge NSArray*)LSSharedFileListCopySnapshot(fileList, NULL);
+    NSArray *listSnapshot = (__bridge_transfer NSArray*)LSSharedFileListCopySnapshot(fileList, NULL);
     for (id itemObject in listSnapshot) {
         LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef) itemObject;
         UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;

+ 10 - 3
ZeroTier One/Network.swift

@@ -177,7 +177,11 @@ class Network: NSObject, NSCoding  {
 
     required init?(coder aDecoder: NSCoder) {
         if aDecoder.containsValueForKey(PropertyKeys.addressesKey) {
-            self.assignedAddresses = aDecoder.decodeObjectForKey(PropertyKeys.addressesKey) as! [String]
+            let addrs = aDecoder.decodeObjectForKey(PropertyKeys.addressesKey) as! [String]
+
+            for a in addrs {
+                self.assignedAddresses.append(a)
+            }
         }
 
         if aDecoder.containsValueForKey(PropertyKeys.bridgeKey) {
@@ -193,7 +197,8 @@ class Network: NSObject, NSCoding  {
         }
 
         if aDecoder.containsValueForKey(PropertyKeys.macKey) {
-            self.mac = aDecoder.decodeObjectForKey(PropertyKeys.macKey) as! String
+            let mac = aDecoder.decodeObjectForKey(PropertyKeys.macKey) as! String
+            self.mac = mac
         }
 
         if aDecoder.containsValueForKey(PropertyKeys.mtuKey) {
@@ -201,7 +206,9 @@ class Network: NSObject, NSCoding  {
         }
 
         if aDecoder.containsValueForKey(PropertyKeys.nameKey) {
-            self.name = aDecoder.decodeObjectForKey(PropertyKeys.nameKey) as! String
+            let name = aDecoder.decodeObjectForKey(PropertyKeys.nameKey) as! String
+
+            self.name = name
         }
 
         if aDecoder.containsValueForKey(PropertyKeys.netconfKey) {

+ 6 - 1
ZeroTier One/NetworkMonitor.swift

@@ -42,8 +42,13 @@ class NetworkMonitor: NSObject {
         let filePath = dataFile()
 
         if NSFileManager.defaultManager().fileExistsAtPath(filePath) {
-            self.savedNetworks = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as! [Network]
+            let networks = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as! [Network]
 
+            self.savedNetworks.removeAll()
+
+            for n in networks {
+                self.savedNetworks.append(n)
+            }
         }
 
         ServiceCom.getNetworkList() { (networkList) -> Void in

+ 1 - 2
ZeroTier One/ServiceCom.swift

@@ -161,9 +161,8 @@ class ServiceCom: NSObject {
 
     static func leaveNetwork(network: String) {
         let urlString = baseURL + "/network/\(network)?auth=\(ServiceCom.getKey())"
-        let url = NSURL(string: urlString)
 
-        if let u = url {
+        if let u = NSURL(string: urlString) {
             let request = NSMutableURLRequest(URL: u)
             request.HTTPMethod = "DELETE"
 

+ 1 - 2
ZeroTier One/ShowNetworksViewController.swift

@@ -112,8 +112,7 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
             cell.addressesField.stringValue = ""
 
             for nw in network.assignedAddresses {
-                cell.addressesField.stringValue += nw
-                cell.addressesField.stringValue += "\n"
+                cell.addressesField.stringValue += "\(nw)\n"
             }