Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a type-safe router #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
3EA4C34219898CDC006A2AA0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4C34119898CDC006A2AA0 /* ViewController.swift */; };
3EA4C34519898CDC006A2AA0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3EA4C34319898CDC006A2AA0 /* Main.storyboard */; };
3EA4C34719898CDC006A2AA0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3EA4C34619898CDC006A2AA0 /* Images.xcassets */; };
627431C71CBDEE2D00684B73 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627431C61CBDEE2D00684B73 /* Router.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -22,6 +23,7 @@
3EA4C34119898CDC006A2AA0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
3EA4C34419898CDC006A2AA0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
3EA4C34619898CDC006A2AA0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
627431C61CBDEE2D00684B73 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -55,6 +57,7 @@
isa = PBXGroup;
children = (
3EA4C33F19898CDC006A2AA0 /* AppDelegate.swift */,
627431C61CBDEE2D00684B73 /* Router.swift */,
3EA4C34119898CDC006A2AA0 /* ViewController.swift */,
3EA4C34319898CDC006A2AA0 /* Main.storyboard */,
3EA4C34619898CDC006A2AA0 /* Images.xcassets */,
Expand Down Expand Up @@ -98,6 +101,7 @@
3EA4C33219898CDC006A2AA0 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = Esri;
TargetAttributes = {
Expand Down Expand Up @@ -143,6 +147,7 @@
buildActionMask = 2147483647;
files = (
3EA4C34219898CDC006A2AA0 /* ViewController.swift in Sources */,
627431C71CBDEE2D00684B73 /* Router.swift in Sources */,
3EA4C34019898CDC006A2AA0 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
40 changes: 40 additions & 0 deletions Basemap Tutorial/swift/MyFirstMapApp/Router.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Router.swift
// MyFirstMapApp
//
// Created by Jeff Kereakoglow on 4/12/16.
// Copyright © 2016 Esri. All rights reserved.
//

import Foundation

/// Usage: `Router.Oceans.URL`
enum Router {
static let baseURLString = "http://services.arcgisonline.com/ArcGIS/rest/services/"

case LightGray
case Ocean
case NatGeo
case Topo
case Imagery

var URL: NSURL {
let path: String = {
switch self {
case .LightGray:
return "Canvas/World_Light_Gray_Base"
case .Ocean:
return "Ocean_Basemap/MapServer"
case .NatGeo:
return "NatGeo_World_Map/MapServer"
case .Topo:
return "World_Topo_Map/MapServer"
case .Imagery:
return "World_Imagery/MapServer"
}
}()

let baseURL = NSURL(string: Router.baseURLString)!
return baseURL.URLByAppendingPathComponent(path)
}
}
10 changes: 5 additions & 5 deletions Basemap Tutorial/swift/MyFirstMapApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class ViewController: UIViewController, AGSMapViewLayerDelegate {

switch sender.selectedSegmentIndex {
case 0: //gray
basemapURL = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer")
basemapURL = Router.LightGray.URL
case 1: //oceans
basemapURL = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer")
basemapURL = Router.Ocean.URL
case 2: //nat geo
basemapURL = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer")
basemapURL = Router.NatGeo.URL
case 3: //topo
basemapURL = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer")
basemapURL = Router.Topo.URL
default: //sat
basemapURL = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer")
basemapURL = Router.Imagery.URL
}

//remove the existing basemap layer
Expand Down