A replacement class for CLLocationManager for when you want to easily fetch the current device location
Swift
Latest commit d305064 Oct 17, 2015 @icanzilb Merge pull request #7 from danielhklein/master
Updated to Swift 2.0
Permalink
Failed to load latest commit information.
DemoAndTests initial commit Sep 19, 2014
.gitignore Initial commit Sep 19, 2014
LICENSE initial commit Sep 19, 2014
OneShotLocationManager.swift Updated to Swift 2.0 Oct 17, 2015
README.md Update README.md May 4, 2015

README.md

OneShotLocationManager (Swift)

ver 0.1

Contents of this readme

Intro

Since CLLocationManager doesn’t support block based APIs sometimes it’s very annoying to setup a delegate and implement all delegate methods if you just want to fetch the current location once and that’s it.

OneShotLocationManager is a class that solves that problem in Swift. Whenever you need to fetch the current device location you just need to create an instance of OneShotLocationManager and call the method to fetch a location. It will request the necessary authorizations and return the current location. Very easy. It just works.

Installation

The infrastructure and best practices for distributing Swift libraries is currently being developed by the developer community during this beta period of the language and Xcode. In the meantime, you can simply download this repository as a ZIP file and drag the OneShotLocationManager.swift file into your Xcode project.


Code Example

How to get the current location

Here's the simplest way to use OneShotLocationManager in Swift:

//in your view controller
var manager: OneShotLocationManager?

override func viewDidLoad() {
  manager = OneShotLocationManager()
  manager!.fetchWithCompletion {location, error in

    // fetch location or an error
    if let loc = location {
      println(location)
    } else if let err = error {
      println(err.localizedDescription)
    }
    self.manager = nil
  }
}

For a complete example app check out the included Xcode project in this repository.

Credit

Author: Marin Todorov

License

OneShotLocationManager is available under the MIT license. See the LICENSE file for more info.