MapKit .PLIST DICTIONARY with INT and STRING-values = multiple annotations WITH Title & Subtitle from plist(根据:MapKit Sample WWDC 2017 - 237)

MapKit .PLIST DICTIONARY with INT and STRING-values = multiple annotations WITH Title & Subtitle from plist (according: MapKit Sample WWDC 2017 - 237)

我使用了 Apples WWDC 2017 的项目 tandm - 237 "Whats new in Mapkit"。

已经有一个 data.plist 带数组 命名的自行车 和额外的词典 有四个项目(键:值 - 对)。

  1. 项目 0 = Dictionary-Nr(来自 0、1、2 ...的多个注释)
  2. item = "key" lat for geo-data with "value" of data-type "number"
  3. item = "key" long for geo-data 经度如上
  4. type = "key" 0(enumeration-defined in Class Bike)用于在 bikeView.swift.
  5. 中声明的不同注释的 tintColor 和 glyphImages

以下示例完美运行:

data.plist 显示:

  -> 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)

这是读取字典第 0 项、第 1 项的代码...:[=​​13=]

// 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
 }
}

我要实现第五个和第六个 (key) named "title" and "subtitle" (with String-values each) to the Dictionary of the data.plist (named item 0), 例如:

  1. 标题="foo"
  2. 副标题="bar"

将以下属性添加到bike.swift

var title: String?
var subtitle: String?

将名为 "title" 和 "subtitle"(每个都有字符串值)的第五个和第六个(键)实现到 data.plist

运行 Tandm.project