Skip to content

Commit

Permalink
Swift 3.0 Xcode 8
Browse files Browse the repository at this point in the history
Code updated for Swift 3.0
  • Loading branch information
jimmyjose-dev committed Sep 19, 2016
1 parent 0143bca commit 1a6c419
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 175 deletions.
261 changes: 130 additions & 131 deletions LocationManager.swift

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions LocationManagerDemo/LocationManagerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@
TargetAttributes = {
BFCFC52D19AEBD4C0089EFCD = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = 3SKRR27PJW;
LastSwiftMigration = 0800;
};
BFCFC53F19AEBD4C0089EFCD = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = 3SKRR27PJW;
LastSwiftMigration = 0800;
TestTargetID = BFCFC52D19AEBD4C0089EFCD;
};
};
Expand Down Expand Up @@ -335,10 +339,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 3SKRR27PJW;
INFOPLIST_FILE = LocationManagerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -348,10 +354,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 3SKRR27PJW;
INFOPLIST_FILE = LocationManagerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
Expand All @@ -360,6 +368,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 3SKRR27PJW;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -371,6 +380,7 @@
INFOPLIST_FILE = LocationManagerDemoTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LocationManagerDemo.app/LocationManagerDemo";
};
name = Debug;
Expand All @@ -379,13 +389,15 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 3SKRR27PJW;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = LocationManagerDemoTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LocationManagerDemo.app/LocationManagerDemo";
};
name = Release;
Expand Down
Binary file not shown.
12 changes: 6 additions & 6 deletions LocationManagerDemo/LocationManagerDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

func applicationWillResignActive(application: UIApplication) {
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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
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) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
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) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
5 changes: 5 additions & 0 deletions LocationManagerDemo/LocationManagerDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>This notification shows for always use</string>
<key>NSLocationUsageDescription</key>
Expand Down
70 changes: 35 additions & 35 deletions LocationManagerDemo/LocationManagerDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele
@IBOutlet var mapView:MKMapView? = MKMapView()
@IBOutlet var textfield:UITextField? = UITextField()

var activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0,0, 50, 50)) as UIActivityIndicatorView
var activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0,y: 0, width: 50, height: 50)) as UIActivityIndicatorView

var locationManager = LocationManager.sharedInstance

Expand All @@ -30,19 +30,19 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele

activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.color = UIColor.blueColor()
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
activityIndicator.color = UIColor.blue
//activityIndicator.backgroundColor = UIColor.brownColor()

locationManager.autoUpdate = true

var address = "1 Infinite Loop, CA, USA"
let address = "1 Infinite Loop, CA, USA"

textfield?.delegate = self
textfield?.text = address
}

@IBAction func reverseGeocode(sender:UIButton) {
@IBAction func reverseGeocode(_ sender:UIButton) {

activityIndicator.startAnimating()
view.addSubview(activityIndicator)
Expand All @@ -56,68 +56,68 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele
locationManager.startUpdatingLocationWithCompletionHandler { (latitude, longitude, status, verboseMessage, error) -> () in

if error != nil {
println(error)
print(error)
} else {
self.plotOnMapWithCoordinates(latitude: latitude, longitude: longitude)
self.plotOnMapWithCoordinates(latitude, longitude)
}
}
}
}

@IBAction func geocode(sender:UIButton) {
@IBAction func geocode(_ sender:UIButton) {

activityIndicator.startAnimating()
view.addSubview(activityIndicator)
var address = textfield?.text!
let address = textfield?.text!
textfield?.resignFirstResponder()

if sender.tag == 0 {
plotOnMapUsingGoogleWithAddress(address!)
plotOnMapUsingGoogleWithAddress(address! as NSString)
} else {
plotOnMapWithAddress(address!)
plotOnMapWithAddress(address! as NSString)
}
}

func locationManagerStatus(status:NSString) {
func locationManagerStatus(_ status:NSString) {

println(status)
print(status)
}

func locationManagerReceivedError(error:NSString) {
func locationManagerReceivedError(_ error:NSString) {

println(error)
print(error)
activityIndicator.stopAnimating()
}

func locationFound(latitude:Double, longitude:Double) {
func locationFound(_ latitude:Double, longitude:Double) {

self.plotOnMapWithCoordinates(latitude: latitude, longitude: longitude)
self.plotOnMapWithCoordinates(latitude, longitude)
}


func textFieldShouldReturn(textField: UITextField) -> Bool {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {

textfield?.resignFirstResponder()

return true
}

func plotOnMapUsingGoogleWithAddress(address:NSString) {
func plotOnMapUsingGoogleWithAddress(_ address:NSString) {

locationManager.geocodeUsingGoogleAddressString(address: address) { (geocodeInfo,placemark, error) -> Void in

self.performActionWithPlacemark(placemark, error: error)
}
}

func plotOnMapWithAddress(address:NSString) {
func plotOnMapWithAddress(_ address:NSString) {

locationManager.geocodeAddressString(address: address) { (geocodeInfo,placemark, error) -> Void in

self.performActionWithPlacemark(placemark, error: error) }
}

func plotOnMapWithCoordinates(#latitude: Double, longitude: Double) {
func plotOnMapWithCoordinates(_ latitude: Double, _ longitude: Double) {

locationManager.reverseGeocodeLocationUsingGoogleWithLatLon(latitude: latitude, longitude: longitude) { (reverseGeocodeInfo, placemark, error) -> Void in

Expand All @@ -126,13 +126,13 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele
}


func performActionWithPlacemark(placemark:CLPlacemark?,error:String?) {
func performActionWithPlacemark(_ placemark:CLPlacemark?,error:String?) {

if error != nil {

println(error)
print(error)

dispatch_async(dispatch_get_main_queue(), { () -> Void in
(DispatchQueue.main).async(execute: { () -> Void in

if self.activityIndicator.superview != nil {

Expand All @@ -141,28 +141,28 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele
}
})
} else {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
DispatchQueue.main.async(execute: { () -> Void in
self.plotPlacemarkOnMap(placemark)
})
}
}

func removeAllPlacemarkFromMap(#shouldRemoveUserLocation:Bool) {
func removeAllPlacemarkFromMap(_ shouldRemoveUserLocation:Bool) {

if let mapView = self.mapView {
for annotation in mapView.annotations{
if shouldRemoveUserLocation {
if annotation as? MKUserLocation != mapView.userLocation {
mapView.removeAnnotation(annotation as! MKAnnotation)
mapView.removeAnnotation(annotation )
}
}
}
}
}

func plotPlacemarkOnMap(placemark:CLPlacemark?) {
func plotPlacemarkOnMap(_ placemark:CLPlacemark?) {

removeAllPlacemarkFromMap(shouldRemoveUserLocation:true)
removeAllPlacemarkFromMap(true)

if self.locationManager.isRunning {
self.locationManager.stopUpdatingLocation()
Expand All @@ -174,16 +174,16 @@ class ViewController: UIViewController, LocationManagerDelegate, UITextFieldDele
self.activityIndicator.removeFromSuperview()
}

var latDelta:CLLocationDegrees = 0.1
var longDelta:CLLocationDegrees = 0.1
let latDelta:CLLocationDegrees = 0.1
let longDelta:CLLocationDegrees = 0.1
var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)

var latitudinalMeters = 100.0
var longitudinalMeters = 100.0
var theRegion:MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(placemark!.location.coordinate, latitudinalMeters, longitudinalMeters)
let latitudinalMeters = 100.0
let longitudinalMeters = 100.0
let theRegion:MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(placemark!.location!.coordinate, latitudinalMeters, longitudinalMeters)

self.mapView?.setRegion(theRegion, animated: true)

self.mapView?.addAnnotation(MKPlacemark(placemark: placemark))
self.mapView?.addAnnotation(MKPlacemark(placemark: placemark!))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LocationManagerDemoTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down

0 comments on commit 1a6c419

Please sign in to comment.