Thank you for your reply!
I did not add too many files until I got some feedback.
I guess that you would like to see RestaurantItem.swift & MapDataManager.swift:
l//
// RestaurantItem.swift
// EatOut
//
// Created by Tony Hudson on 12/07/2021.
//
import UIKit
import MapKit
class RestaurantItem: NSObject, MKAnnotation {
var name: String?
var cuisines: [String] = []
var lat: Double?
var long: Double?
var address: String?
var postalCode: String?
var state: String?
var imageURL: String?
var restaurantID: Int?
init (dict: [String: AnyObject]) {
if let lat = dict["lat"] as? Double { self.lat = lat}
if let long = dict["long"] as? Double { self.long = long}
if let name = dict["name"] as? String { self.name = name}
if let cuisines = dict["cuisines"] as? [String] { self.cuisines = cuisines}
if let address = dict["address"] as? String { self.address = address}
if let postalCode = dict["postalCode"] as? String { self.postalCode = postalCode}
if let state = dict["state"] as? String { self.state = state}
if let image = dict["imageURL"] as? String { self.imageURL = image}
if let id = dict["id"] as? Int { self.restaurantID = id}
}
var coordinate: CLLocationCoordinate2D {
guard let lat = lat, let long = long else {
return CLLocationCoordinate2D()
}
return CLLocationCoordinate2D(latitude: lat, longitude: long)
}
var title: String? {
return name
}
var subtitle: String? {
if cuisines.isEmpty { return ""}
else if cuisines.count == 1 { return cuisines.first}
else { return cuisines.joined(separator: ", ")
}
}
}
// MapDataManager.swift
// EatOut
//
// Created by Tony Hudson on 12/07/2021.
//
import Foundation
import MapKit
class MapDataManager: DataManager {
fileprivate var items: [RestaurantItem] = []
var annotations: [RestaurantItem] {
return items
}
func fetch(completion: (_ annotations: [RestaurantItem]) -> ()){
if items.count > 0 { items.removeAll() }
for data in load(file: "MapLocations") {
items.append(RestaurantItem(dict: data))
}
completion(items)
}
func currentRegion(latDelta: CLLocationDegrees, longDelta: CLLocationDegrees) -> MKCoordinateRegion {
guard let item = items.first else {
return MKCoordinateRegion()
}
let span = MKCoordinateSpan(latitudeDelta: latDelta, longitudeDelta: longDelta)
return MKCoordinateRegion(center: item.coordinate, span: span)
}
}
Could you explain what you said that annotations was not used?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: