This repository was archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaces.swift
More file actions
41 lines (32 loc) · 1.27 KB
/
Copy pathPlaces.swift
File metadata and controls
41 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Places.swift
// MapKit Starter
//
// Created by Pranjal Satija on 10/25/16.
// Copyright © 2016 Pranjal Satija. All rights reserved.
//
import MapKit
@objc class Place: NSObject {
var title: String?
var subtitle: String?
var coordinate: CLLocationCoordinate2D
init(title: String?, subtitle: String?, coordinate: CLLocationCoordinate2D) {
self.title = title
self.subtitle = subtitle
self.coordinate = coordinate
}
static func getPlaces() -> [Place] {
guard let path = Bundle.main.path(forResource: "Places", ofType: "plist"), let array = NSArray(contentsOfFile: path) else { return [] }
var places = [Place]()
for item in array {
let dictionary = item as? [String : Any]
let title = dictionary?["title"] as? String
let subtitle = dictionary?["description"] as? String
let latitude = dictionary?["latitude"] as? Double ?? 0, longitude = dictionary?["longitude"] as? Double ?? 0
let place = Place(title: title, subtitle: subtitle, coordinate: CLLocationCoordinate2DMake(latitude, longitude))
places.append(place)
}
return places as [Place]
}
}
extension Place: MKAnnotation {}