From 44854c3cd4133c18bff3cc51f29417c86576c950 Mon Sep 17 00:00:00 2001 From: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Date: Sun, 5 Apr 2020 16:04:43 +0100 Subject: [PATCH] added extra checks for main thread, and some badges to README --- README.md | 5 ++++- Sources/RKPointPin/RKPointPin.swift | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2aef82a..d198611 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ RKPointPin is a UIView which sticks to an `ARView` and points at a chosen entity within the scene, with options to hide the pin when near the center of the screen, or perform any custom actions. +[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-v1.0.0-orange.svg?style=flat)](https://github.com/apple/swift-package-manager) +[![Swift 5.2](https://img.shields.io/badge/Swift-5.2-orange.svg?style=flat)](https://swift.org/) + ![RKPointPin Example](media/pin_512.gif) ## Minimum Requirements @@ -29,4 +32,4 @@ self.arView.addSubview(rkPin) rkPin.targetEntity = boxEntity ``` -By default the RKPointPin will be visible all the time, but if you want the pin to hide when in the center, set the `focusPercentage` to a value ranging from 0 to 1. If `focusPercentage` is set to 1, then the pin will only appear when the `targetEntity` is outside of the view, as everything from the edges inwards is considered the focus area. +By default the RKPointPin will be visible all the time, but if you want the pin to hide when in the center, set the `focusPercentage` to a value ranging from 0 to 1. If `focusPercentage` is set to 1, then the pin will only appear when the `targetEntity` is outside of the view, as everything from the edges inwards is considered the focus area. diff --git a/Sources/RKPointPin/RKPointPin.swift b/Sources/RKPointPin/RKPointPin.swift index 82acf35..94690a8 100644 --- a/Sources/RKPointPin/RKPointPin.swift +++ b/Sources/RKPointPin/RKPointPin.swift @@ -111,7 +111,14 @@ public class RKPointPin: UIView { private func resetCancellable() { self.cancellable?.cancel() - guard let arView = self.arView, self.targetEntity != nil else { + if self.targetEntity == nil { + return + } + if !Thread.isMainThread { + print("RKPointPin ERROR: targetEntity should set from main thread") + return + } + guard let arView = self.arView else { return } self.cancellable = arView.scene.subscribe( @@ -168,7 +175,7 @@ public class RKPointPin: UIView { private func updatePos() { if !Thread.isMainThread { - print("RKPointPin: Should be on main thread") + print("RKPointPin ERROR: Should be on main thread") return } guard let arView = self.arView else {