我使用了来自Apple WWDC 2017的Project tandm-237 “ Mapkit的新增功能”。
已经有一个带有数组的data.plist 命名自行车 和其他字典 有四个项目(键:值-对)。
以下示例很完美:
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”(每个具有字符串值),例如: