Skip to content

Instantly share code, notes, and snippets.

@regnerjr
Created August 15, 2014 02:38
Show Gist options
  • Save regnerjr/9794adb6c87ed1ceeeb7 to your computer and use it in GitHub Desktop.
Save regnerjr/9794adb6c87ed1ceeeb7 to your computer and use it in GitHub Desktop.
Chapter 4 - BNR iOS Programming - Swift
//
// ViewController.swift
// WhereAmI
//
// Created by John Regner on 8/13/14.
// Copyright (c) 2014 In Your Dreams Software. All rights reserved.
//
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
//Configure Location Manager
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
locationManager.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
///MARK: CLLocationManager Delegate Methods
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
println("location changed")
println("number of locations \(locations.count)")
for index in 0..<locations.count {
println("\(locations[index] as CLLocation)")
}
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("Could not find location: \(error)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment