Continuous Xcode Error
Can anyone else explain as to why I would always receive the error of "Entry point (_main) undefined. for architecture arm64" when I ran the build?
import Foundation
import CoreLocation
func getLocation(from address: String, completion: @escaping (Result<(latitude: Double, longitude: Double), Error>) -> Void) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address) { placemarks, error in
guard let placemark = placemarks?.first, error == nil else {
completion(.failure(error ?? NSError(domain: "getLocation", code: 0, userInfo: nil)))
return
}
let locationCoords = (placemark.location?.coordinate.latitude ?? 0, placemark.location?.coordinate.longitude ?? 0)
completion(.success(locationCoords))
}
}
func getNearbyServices(latitude: Double, longitude: Double, serviceType: String, completion: @escaping (Result<[String], Error>) -> Void) {
let url = "https://api.openstreetmap.org/api/0.6/\(serviceType).json?lat=\(latitude)&***=\(longitude)"
let request = URLRequest(url: URL(string: url)!)
URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
completion(.failure(error ?? NSError(domain: "getNearbyServices", code: 0, userInfo: nil)))
return
}
do {
let json = try JSONSerialization.jsonObject(with: data, options: [])
if let jsonDictionary = json as? [String: Any], let elements = jsonDictionary["elements"] as? [[String: Any]] {
var serviceNames: [String] = []
for element in elements {
if let name = element["tags"] as? [String: String], let serviceName = name["name"], let phoneNumber = name["phone"] {
serviceNames.append("\(serviceName) (\(phoneNumber))")
}
}
completion(.success(serviceNames))
}
} catch {
completion(.failure(error))
}
}.resume()
}
func teachAboutStrokes() {
// ...
print("Let's locate nearby emergency services.")
if let address = readLine() {
getLocation(from: address) { result in
switch result {
case .success(let location):
let serviceType = "amenity=emergency"
getNearbyServices(latitude: location.latitude, longitude: location.longitude, serviceType: serviceType) { result in
switch result {
case .success(let services):
print("Here are the nearby emergency services:")
for service in services {
print("- \(service)")
}
case .failure(let error):
print("Error getting nearby services: \(error.localizedDescription)")
}
}
case .failure(let error):
print("Error getting location: \(error.localizedDescription)")
}
}
}
}
func main() {
teachAboutStrokes()
}
MacBook Air Apple Silicon