Skip To Content ArcGIS for Developers Sign In Dashboard


You will learn: how to build an app that loads and displays a layer from ArcGIS Online.

The ArcGIS Runtime SDK for iOS allows you to access items (such as layers) stored in ArcGIS Online by their item identifier. Feature layers can store geographic features (points, lines, polygons), edit or update attributes, and synchronize changes. As demonstrated in the tutorial Display a web map, you can load and display an existing web map that was pre-configured with a basemap and layers. Alternatively, you may wish to load one or more layers from ArcGIS Online and create a map with code. To do so, you need to access each item by ID. You can find an item's ID by browsing to the item on ArcGIS Online and identifying it at the end of the URL, e.g. You can also publish your own feature layer to ArcGIS Online using the Create a new dataset data tutorial.

In this tutorial you will learn how to access a layer stored in ArcGIS Online. You will open the layer using its identifier and display its contents on a map.

Before you begin

Make sure you have installed the latest version of Xcode.

Reuse the starter project

If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open the .xcodeproj file in Xcode. Run and verify the map displays in the device simulator.

In your browser, go to the Trailheads Styled layer on ArcGIS Online and find the item ID at the end of the URL. It should be 2e4b3df6ba4b44969a3bc9827de746b3.


  1. Open the ViewController.swift file, update the setupMap() method to create an AGSFeatureLayer that is hosted at an AGSPortal identified by a unique AGSPortalItem item ID. Add the feature layer to the map's operational layers.

    /** UPDATE **/
    private func setupMap() {
      // Create a map.
      let map = AGSMap(
          basemapType: .navigationVector,
          latitude: 34.09042,
          longitude: -118.71511,
          levelOfDetail: 10
      // Build a trailheads feature layer from a portal item.
      let trailheads: AGSFeatureLayer = {
          let portal = AGSPortal.arcGISOnline(withLoginRequired: false)
          let item = AGSPortalItem(portal: portal, itemID: "2e4b3df6ba4b44969a3bc9827de746b3")
          return AGSFeatureLayer(item: item, layerID: 0)
      // Add the trailheads layer to the map's operational layers.
      // Set the map. = map
  2. Press Command-R to run the app in the iOS Simulator.

    (Note, as of 100.8 Runtime supports Metal. In order to run your app in a simulator you must meet some minimum requirements. You must be developing on macOS Catalina, using Xcode 11, and simulating iOS 13.)

Congratulations, you're done!

Your app should display a map with the trailheads centered on the Santa Monica Mountains. Compare your solution with our completed solution project.


Use your portal item

Instead of using the portal item we used above, use the one you made in the data tutorial Create a new dataset.

In Step 1 above, replace the itemID parameter with the ID of your portal item.

Load a portal item using its entire URL

Instead of creating a portal and then a portal item like we did in the tutorial, create just a portal item with its entire URL using the following initializer available in the SDK. You don't need to create an AGSPortal object.

    let itemURL = URL(string: "")!
    let item = AGSPortalItem(url: itemURL)

As before, create a layer from the portal item and add it to the map.

Discover data

If you have not already done so, visit the Discover data tutorial and search for interesting open data you could add in another layer in your app.