Giter Club home page Giter Club logo

oneshotlocationmanager's Introduction

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 {
      prinln(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.

oneshotlocationmanager's People

Contributors

icanzilb avatar

Watchers

Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.