Initialize the map view such that a map instance is created for rendering on the client device

The contents of this guide apply to Xcode 10 and the iOS 12 SDK.

Sample Project in the HERE iOS SDK

A copy of the Xcode project described in this tutorial is available in the sample-apps folder in your HERE iOS SDK package. To run the project, double-click on SwiftHelloMap.xcodeproj and follow the instructions in the README.txt file.

In the next dialog, enter your Product Name (such as HelloMap) and Organization Identifier (such as edu.self).

Choose "Swift" under Language, then click Next.

Navigate to the directory where you want your project to be stored and then select Create.

The next step is to configure this project to use the HERE SDK.

Configure the Application

Extract the HERE iOS SDK archive to somewhere in your local file system.

Add the NMAKit framework to your Xcode project. To add the NMAKit framework to your Xcode project, click on your app target and choose the "General" tab. Find the section called "Embedded Binaries", click the plus (+) sign, and then click the "Add Other" button. From the file dialog box, select the "NMAKit.framework" folder. Ensure that the "Copy items if needed" and "Create folder reference" options are selected, then click Finish. Figure 1. Add File to Target

Ensure that NMAKit.framework appears in the "Embedded Binaries" and the "Linked Frameworks and Libraries" sections. Figure 2. Embedded Binaries

Run the application. From the Xcode menu bar, select Product > Run. Ensure that the project runs in the iOS Simulator without errors.

The HERE iOS SDK is now ready for use in your Xcode project. Now that you have your project configured to work with the HERE SDK, try extending the sample application to render a map.

Create the Map View

In this section, we utilize the NMAMapView and NMAGeoCoordinates classes to render a Map.

Create an NMAMapView.

Select Main.storyboard in the navigator, then open the Utilities view by pressing the key combination Command + Option + Control + 3. Drag and drop a View object from the Object Library onto the View Controller. If necessary, resize the View so it takes up the entire viewable area.

In the Interface Builder, click on the created View and then open the Identity Inspector in the Utilities view by pressing the key combination Command + Option + 3. Change the class value from UIView to NMAMapView and press return. In the Document Outline, you should see that the name of the View has changed from to View to Map View.

Figure 3. MapView

Create an outlet to NMAMapView in ViewController.

Select Main.storyboard in the navigator.

Press Command + Option + Return to open the Assistant Editor. It should show ViewController.swift.

Add the following import statement to the top of this file:

import NMAKit

Hold the Control key on the keyboard and click to drag from the Map View to the interface block in ViewController.swift. You should see a blue line and tooltip which says "Insert Outlet or Outlet Connection". Release the mouse button and a dialog appears, allowing you to create an outlet.

Name the outlet mapView, keep the other default options and then select Connect.

Figure 4. Create an Outlet

Now an outlet to NMAMapView is set. The modified file should be as follows: