Skip to content

Commit

Permalink
Timer callbacks need weak references
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilot-Marc committed Nov 24, 2019
1 parent 1134549 commit 2a8d0b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 6 additions & 11 deletions ARKit+CoreLocation/POIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ class POIViewController: UIViewController {
self.restartAnimation()
}

updateInfoLabelTimer = Timer.scheduledTimer(timeInterval: 0.1,
target: self,
selector: #selector(POIViewController.updateInfoLabel),
userInfo: nil,
repeats: true)
updateInfoLabelTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in
self?.updateInfoLabel()
}

// Set to true to display an arrow which points north.
// Checkout the comments in the property description and on the readme on this.
Expand All @@ -97,12 +95,9 @@ class POIViewController: UIViewController {
mapView.isHidden = !showMap

if showMap {
updateUserLocationTimer = Timer.scheduledTimer(
timeInterval: 0.5,
target: self,
selector: #selector(POIViewController.updateUserLocation),
userInfo: nil,
repeats: true)
updateUserLocationTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
self?.updateUserLocation()
}

routes?.forEach { mapView.addOverlay($0.polyline) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ public final class SceneLocationManager {
public extension SceneLocationManager {
func run() {
pause()
updateEstimatesTimer = Timer.scheduledTimer(
timeInterval: 0.1,
target: self,
selector: #selector(SceneLocationManager.updateLocationData),
userInfo: nil,
repeats: true)
if #available(iOS 11.0, *) {
updateEstimatesTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
self?.updateLocationData()
}
} else {
assertionFailure("Needs iOS 9 and 10 support")
}
}

func pause() {
Expand Down

0 comments on commit 2a8d0b5

Please sign in to comment.