Question: how can i fix this swift code I am self learning swift. I do know how to solve this error in c++ but don't really
how can i fix this swift code
I am self learning swift. I do know how to solve this error in c++ but don't really know how to fix it in this language.
i get this error -> Use of unresolved identifier 'calculateDistance'
import Foundation
struct location {
let x: Int
let y: Int
}
struct deliveryArea {
let center: location
let radius: Double
func contains (_ location: location) -> Bool {
let distanceToStore = calculateDistance(from: location, to: center)
if distanceToStore < self.radius {
return true
}
}
}
let restaurant1 = deliveryArea(center: location(x: 2, y: 3), radius: 2.5)
let restaurant2 = deliveryArea(center: location(x: 7, y: 8), radius: 1.5)
let restaurants = [restaurant1, restaurant2]
func calculateDistance (from source: location, to target: location) -> Double {
let distanceX = Double(source.x - target.x)
let distanceY = Double(source.y - target.y)
let result = sqrt(pow(distanceX, 2.0) + pow(distanceY, 2.0))
return result
}
func isInDeliveryLocation (location: location) -> Bool {
for restaurant in restaurants {
if restaurant.contains(location) {
return true
}
}
return false
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
