Browse Source

Fix log timer in example app not firing

Tanner Bennett 3 years ago
parent
commit
2c510c8ca1
1 changed files with 10 additions and 14 deletions
  1. 10 14
      Example/FLEXample/AppDelegate.swift

+ 10 - 14
Example/FLEXample/AppDelegate.swift

@@ -21,11 +21,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         UserDefaults.standard.set("foo", forKey: "FLEXamplePrefFoo")
         
         // To show off the system log viewer, send 10 example log messages at 3 second intervals
-        self.repeatingLogExampleTimer = Timer(
-            timeInterval: 3, target: self,
-            selector: #selector(sendExampleLogMessage),
-            userInfo: nil, repeats: true
-        )
+        self.repeatingLogExampleTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { [weak self] (_) in
+            if let self = self {
+                NSLog("Example log \(self.exampleLogSent)")
+        
+                self.exampleLogSent += 1
+                if self.exampleLogSent > self.exampleLogLimit {
+                    self.repeatingLogExampleTimer.invalidate()
+                }
+            }
+        }
         
         // To show off the network logger, send several misc network requests
         MiscNetworkRequests.sendExampleRequests()
@@ -56,13 +61,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     
     let exampleLogLimit = 10
     var exampleLogSent = 0
-
-    func sendExampleLogMessage() {
-        NSLog("Example log \(self.exampleLogSent)")
-        
-        self.exampleLogSent += 1
-        if self.exampleLogSent > self.exampleLogLimit {
-            self.repeatingLogExampleTimer.invalidate()
-        }
-    }
 }