I used the Project tandm from Apples WWDC 2017 - 237 "What's new in Mapkit".
There is already a data.plist with an array named bikes and additional dictionaries with four items (key : values -Pairs).
Following example works perfect:
data.plist shows:
-> Root - dictionary
-> bikes - array
-> item 0 - dictionary (Annotation Nr. 1)
-> lat - number 50.12345 (latitude of Annotation Nr.1
-> long - number 6.12345 (longitude of Annot. Nr. 1)
-> type - number 1 (two different 0 or 1)
Here is the code which reads the dictionaries item 0, item 1...:
// Class bike.swift
import MapKit
class Bike: MKPointAnnotation {
enum BikeType: Int {
case unicycle
case bicycle
}
var type: BikeType = .tricycle
func bikes(fromDictionaries dictionaries: [[String: NSNumber]]) -> [Museum] {
let bikes = dictionaries.map { item -> Bike in
let bike = Bike()
bike.coordinate = CLLocationCoordinate2DMake(item["lat"]!.doubleValue, item["long"]!.doubleValue)
bike.type = BikeType(rawValue: item["type"]!.intValue)!
return bike
}
return bike
}
}
I want to implement a fifth and sixth (key) named "title" and "subtitle" (with String-values each) to the Dictionary of the data.plist (named item 0), for example:
Add the following property to bike.swift
var title: String?
var subtitle: String?
Implement a fifth and sixth (key) named "title" and "subtitle" (with String-values each) to the data.plist
Run Tandm.project