Skip to content

Commit

Permalink
Adds some getters and setters. Refs #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
gradha committed May 31, 2015
1 parent 227291a commit 81d6797
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions src/SGPS.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,78 @@
import Foundation
import CoreLocation

public class Test

enum Accuracy
{
init(a: String) {
println("Hello \(a)")
}
case High, Medium, Low
}

@objc public class SGPS
@objc public class SGPS : NSObject, CLLocationManagerDelegate
{
private let _GPS_IS_ON_KEY = "gps_is_on"
private let _KEY_SAVE_SINGLE_POSITION = "save_single_positions"

static private let cInstance: SGPS = SGPS();
static private var cSaveAllPositions: Bool = false
private var mSaveAllPositions: Bool {
get { return self.mSaveAllPositions }
set {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setBool(newValue, forKey:_KEY_SAVE_SINGLE_POSITION)
defaults.synchronize()
}
}

private var mManager: CLLocationManager
private var mAccuracy: Accuracy

static func get() -> SGPS {
static func get() -> SGPS
{
return cInstance
}

public init()
override public init()
{
let defaults = NSUserDefaults.standardUserDefaults()
println("Initializing SGPS")
mManager = CLLocationManager()
//assert(nil !== mManager) TODO: Why does the check fail?
mAccuracy = .High
super.init()

// Set no filter and try to get the best accuracy possible.
mManager.distanceFilter = kCLDistanceFilterNone
mManager.desiredAccuracy = kCLLocationAccuracyBest
mManager.delegate = self

let defaults = NSUserDefaults.standardUserDefaults()
if defaults.boolForKey(_GPS_IS_ON_KEY) {
start();
start()
}
mSaveAllPositions = defaults.boolForKey(_KEY_SAVE_SINGLE_POSITION)
}

deinit {
stop()
//mManager = nil
}

public var mGpsIsOn: Bool {
get {
return self.mGpsIsOn
}
set {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setBool(newValue, forKey:_GPS_IS_ON_KEY)
defaults.synchronize()
}
SGPS.cSaveAllPositions = defaults.boolForKey(_KEY_SAVE_SINGLE_POSITION);
}

public func start()
{
println("Starting!");
println("Starting!")
}

public func stop()
{
println("Stopping")
}
}

0 comments on commit 81d6797

Please sign in to comment.