具有INT和STRING值的MapKit .PLIST字典= plist中带有标题和字幕的多个注释(根据:MapKit示例WWDC 2017-237)

时间:2018-12-24 17:20:20

标签: swift annotations mapkit plist

我使用了来自Apple WWDC 2017的Project tandm-237 “ Mapkit的新增功能”。

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

  1. 项目0 = Dictionary-Nr(0、1、2 ...的多个注释)
  2. item =“ key” lat,用于数据类型为“数字”的地理数据
  3. item =“ key”对于上述地理数据经度很长
  4. type =“ key” 0(在Bike类中枚举定义),用于tintColor和glyphImages(用于在bikeView.swift中声明的不同注释)。

以下示例很完美:

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 ...的代码:

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

我想实施第五和第六 (键)分别命名为data.plist(名称为0的字典)的字典的“ title”和“ subtitle”(每个具有字符串值),例如:

  1. title =“ foo”
  2. subtitle =“ bar”

1 个答案:

答案 0 :(得分:0)

将以下属性添加到bike.swift

var title: String?
var subtitle: String?

将名为“ title”和“ subtitle”(分别具有字符串值)的第五个和第六个(键)添加到data.plist

enter image description here

运行Tandm.project

enter image description here