Data structure
Firstly, we define a typealias
for the data structure added to both the watch and the phone targets, that will hold the location data, by following these steps:
Shared constants
In the downloaded project, create a new Swift file, name it SharedConstants.swift
, being sure to select both targets, Plot Buddy and Plot Buddy WatchKit Extension, as illustrated here:
Select this file in the project navigator and replace the import
statement with the following code:
Import WatchKit typealias LocationSet = [CLLocation] //1 let ApplicationContextDataKey = "Data" //2
Our
LocationSet
data structure is nothing more than an array ofCLLocation
objects, which is the type returned by our calls to the Core Location framework.For the sake of safety, we define a String constant for use as the
Key
to the data object passed from watch to phone in theApplicationContext
.