Skip to content

Commit

Permalink
Adds Swiftlint support
Browse files Browse the repository at this point in the history
Adds a very basic set of Swiftlint rules, and makes sure that the project and demo app follow them. More details on Swiftlint are available at https://github.com/realm/SwiftLint
  • Loading branch information
aaronbrethorst committed May 29, 2018
1 parent c175d21 commit 7716db6
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 300 deletions.
7 changes: 7 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
disabled_rules:
- file_length
- identifier_name
- line_length
- shorthand_operator
- type_body_length
function_body_length: 70
18 changes: 18 additions & 0 deletions ARKit+CoreLocation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
49A3FBD41F09988100AA59C8 /* Sources */,
49A3FBD51F09988100AA59C8 /* Frameworks */,
49A3FBD61F09988100AA59C8 /* Resources */,
935FB3C020BD304200F6A081 /* Swiftlint */,
);
buildRules = (
);
Expand Down Expand Up @@ -177,6 +178,23 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
935FB3C020BD304200F6A081 /* Swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = Swiftlint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
49A3FBD41F09988100AA59C8 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
40 changes: 7 additions & 33 deletions ARKit+CoreLocation/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

print("NEW SESSION")

UIApplication.shared.isIdleTimerDisabled = true

self.window = UIWindow(frame: UIScreen.main.bounds)

self.window!.makeKeyAndVisible()

if #available(iOS 11.0, *) {
let vc = ViewController()
self.window!.rootViewController = vc
} else {
self.window!.rootViewController = NotSupportedViewController()
self.window!.rootViewController = NotSupportedViewController()
}

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
return true
}


}

11 changes: 5 additions & 6 deletions ARKit+CoreLocation/NotSupportedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
import UIKit

class NotSupportedViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = .white

let label = UILabel()
label.textAlignment = .center
label.text = "iOS 11+ required"

self.view.addSubview(label)

label.translatesAutoresizingMaskIntoConstraints = false
label.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
label.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
}

}
4 changes: 2 additions & 2 deletions ARKit+CoreLocation/Source/CGPoint+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ extension CGPoint {
static func pointWithVector(vector: SCNVector3) -> CGPoint {
return CGPoint(x: CGFloat(vector.x), y: CGFloat(0 - vector.z))
}

func radiusContainsPoint(radius: CGFloat, point: CGPoint) -> Bool {
let x = pow(point.x - self.x, 2)
let y = pow(point.y - self.y, 2)
let radiusSquared = pow(radius, 2)

return x + y <= radiusSquared
}
}
40 changes: 20 additions & 20 deletions ARKit+CoreLocation/Source/CLLocation+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct LocationTranslation {
public var latitudeTranslation: Double
public var longitudeTranslation: Double
public var altitudeTranslation: Double

public init(latitudeTranslation: Double, longitudeTranslation: Double, altitudeTranslation: Double) {
self.latitudeTranslation = latitudeTranslation
self.longitudeTranslation = longitudeTranslation
Expand All @@ -26,51 +26,51 @@ public extension CLLocation {
public convenience init(coordinate: CLLocationCoordinate2D, altitude: CLLocationDistance) {
self.init(coordinate: coordinate, altitude: altitude, horizontalAccuracy: 0, verticalAccuracy: 0, timestamp: Date())
}

///Translates distance in meters between two locations.
///Returns the result as the distance in latitude and distance in longitude.
public func translation(toLocation location: CLLocation) -> LocationTranslation {
let inbetweenLocation = CLLocation(latitude: self.coordinate.latitude, longitude: location.coordinate.longitude)

let distanceLatitude = location.distance(from: inbetweenLocation)

let latitudeTranslation: Double

if location.coordinate.latitude > inbetweenLocation.coordinate.latitude {
latitudeTranslation = distanceLatitude
} else {
latitudeTranslation = 0 - distanceLatitude
}

let distanceLongitude = self.distance(from: inbetweenLocation)

let longitudeTranslation: Double

if self.coordinate.longitude > inbetweenLocation.coordinate.longitude {
longitudeTranslation = 0 - distanceLongitude
} else {
longitudeTranslation = distanceLongitude
}

let altitudeTranslation = location.altitude - self.altitude

return LocationTranslation(
latitudeTranslation: latitudeTranslation,
longitudeTranslation: longitudeTranslation,
altitudeTranslation: altitudeTranslation)
}

public func translatedLocation(with translation: LocationTranslation) -> CLLocation {
let latitudeCoordinate = self.coordinate.coordinateWithBearing(bearing: 0, distanceMeters: translation.latitudeTranslation)

let longitudeCoordinate = self.coordinate.coordinateWithBearing(bearing: 90, distanceMeters: translation.longitudeTranslation)

let coordinate = CLLocationCoordinate2D(
latitude: latitudeCoordinate.latitude,
longitude: longitudeCoordinate.longitude)

let altitude = self.altitude + translation.altitudeTranslation

return CLLocation(coordinate: coordinate, altitude: altitude, horizontalAccuracy: self.horizontalAccuracy, verticalAccuracy: self.verticalAccuracy, timestamp: self.timestamp)
}
}
Expand All @@ -79,26 +79,26 @@ extension Double {
func metersToLatitude() -> Double {
return self / (6360500.0)
}

func metersToLongitude() -> Double {
return self / (5602900.0)
}
}

public extension CLLocationCoordinate2D {
public func coordinateWithBearing(bearing:Double, distanceMeters:Double) -> CLLocationCoordinate2D {
public func coordinateWithBearing(bearing: Double, distanceMeters: Double) -> CLLocationCoordinate2D {
//The numbers for earth radius may be _off_ here
//but this gives a reasonably accurate result..
//Any correction here is welcome.
let distRadiansLat = distanceMeters.metersToLatitude() // earth radius in meters latitude
let distRadiansLong = distanceMeters.metersToLongitude() // earth radius in meters longitude

let lat1 = self.latitude * Double.pi / 180
let lon1 = self.longitude * Double.pi / 180

let lat2 = asin(sin(lat1) * cos(distRadiansLat) + cos(lat1) * sin(distRadiansLat) * cos(bearing))
let lon2 = lon1 + atan2(sin(bearing) * sin(distRadiansLong) * cos(lat1), cos(distRadiansLong) - sin(lat1) * sin(lat2))

return CLLocationCoordinate2D(latitude: lat2 * 180 / Double.pi, longitude: lon2 * 180 / Double.pi)
}
}
41 changes: 20 additions & 21 deletions ARKit+CoreLocation/Source/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ protocol LocationManagerDelegate: class {
///Does not contain anything related to ARKit or advanced location
class LocationManager: NSObject, CLLocationManagerDelegate {
weak var delegate: LocationManagerDelegate?

private var locationManager: CLLocationManager?

var currentLocation: CLLocation?

var heading: CLLocationDirection?
var headingAccuracy: CLLocationDegrees?

override init() {
super.init()

self.locationManager = CLLocationManager()
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager!.distanceFilter = kCLDistanceFilterNone
Expand All @@ -37,54 +37,53 @@ class LocationManager: NSObject, CLLocationManagerDelegate {
self.locationManager!.delegate = self
self.locationManager!.startUpdatingHeading()
self.locationManager!.startUpdatingLocation()

self.locationManager!.requestWhenInUseAuthorization()

self.currentLocation = self.locationManager!.location
}

func requestAuthorization() {
if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse {
return
}

if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.denied ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.restricted {
return
}

self.locationManager?.requestWhenInUseAuthorization()
}
//MARK: - CLLocationManagerDelegate

// MARK: - CLLocationManagerDelegate

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
for location in locations {
self.delegate?.locationManagerDidUpdateLocation(self, location: location)
}

self.currentLocation = manager.location
}

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
if newHeading.headingAccuracy >= 0 {
self.heading = newHeading.trueHeading
} else {
self.heading = newHeading.magneticHeading
}

self.headingAccuracy = newHeading.headingAccuracy

self.delegate?.locationManagerDidUpdateHeading(self, heading: self.heading!, accuracy: newHeading.headingAccuracy)
}

func locationManagerShouldDisplayHeadingCalibration(_ manager: CLLocationManager) -> Bool {
return true
}
}

Loading

0 comments on commit 7716db6

Please sign in to comment.