Overview

You will learn: how to create a simple starter app that displays a basemap. This template project will be used in subsequent labs.

With the ArcGIS Runtime SDK for macOS, it is easy to create a native mapping app that displays a basemap. In this lab, you will use the macOS SDK to build a simple mapping app that we will use as a starting point for the other macOS labs. This lab demonstrates the basic SDK setup for macOS Xcode projects.

These labs assume you're developing with Xcode and have downloaded and installed the ArcGIS Runtime SDK for macOS to the default location. For a more detailed walk-through of these steps (and to see how to use Cocoapods instead), see Add a map to your app.

Before you begin

Download and install the ArcGIS Runtime SDK for macOS by following the instructions detailed at Install the SDK.

You will need a developer subscription to download the SDK. If you haven't already, sign up for free.

Steps

Create a starter app

  1. Open Xcode and create a new macOS Swift Cocoa Application named to ArcGIS Starter App.

Hook up the ArcGIS Runtime SDK

  1. In the project target's Build Settings, set Framework Search Paths to $(HOME)/Library/SDKs/ArcGIS/macOS/Frameworks/Static.

  2. In the project target's Build Settings, set Other Linker Flags to -ObjC -framework ArcGIS -l c++.

  3. Add the ArcGIS resource bundle to the project (found in $(HOME)/Library/SDKs/ArcGIS/macOS/Frameworks/Static/ArcGIS.framework/Versions/Current/Resources/).

  4. Configure App Transport Security. Right-click on info.plist file in the Project Navigator and Open As > / Source Code. Edit the file just after the opening top-level <dict> tag and add the following XML:

    <dict>
        <!-- ADD -->
        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSExceptionDomains</key>
            <dict>
                <key>arcgisonline.com</key>
                <dict>
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                </dict>
                <key>arcgis.com</key>
                <dict>
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                </dict>
            </dict>
        </dict>
        ...
    

Add a map to your app

Now that you've created an app and included ArcGIS Runtime SDK for macOS, the next step is to add a AGSMapView to the storyboard.

  1. Open Main.storyboard in the project navigator and add a new Custom View to the parent view. Add constraints so the new view fills the parent view.

  2. With the new view selected, in Xcode's app menu, select View > Utilities > Show Identity Inspector and in the Identity Inspector (top-right), set the Class attribute to AGSMapView.

  3. Import the ArcGIS SDK into ViewController.swift and add an @IBOutlet named mapView to the ViewController class.

    ...
    import Cocoa
    /*** ADD ***/
    import ArcGIS
    
    class ViewController: NSViewController {
    
        /*** ADD ***/
        @IBOutlet weak var mapView: AGSMapView!
    
        override func viewDidLoad() {
    
        ...
    
  4. Create a new AGSMap with a .navigationVector basemap and set the AGSMapView to use it.

        ...
        override func viewDidLoad() {
            super.viewDidLoad()
    
            /*** ADD ***/
            let map = AGSMap(basemapType: .navigationVector, latitude: 34.05293, longitude: -118.24368, levelOfDetail: 9)
    
            mapView.map = map
        }
    
  5. Open the Main.storyboard and right click on the blue View Controller icon. Drag the mapView outlet connector to the AGSMapView.

  6. Now press Command-R to run the app.

Congratulations, you're done!

Your app should run and display the basemap.

Your project should look something like this. We will refer back to this project as the starting template for many of the macOS labs.

Challenge

Explore basemaps

Visit the macOS SDK documentation to learn more about the different types of basemaps available. Try some different basemap types such as .lightGrayCanvasVector, .topographicVector or .streetsWithReliefVector and pick your favorite basemap.

Change view

Try different settings for the initial view by changing the latitude, longitude, and level of detail.