gpt4 book ai didi

ios - 使用 swift 和 market 查找附近的酒吧

转载 作者:行者123 更新时间:2023-11-28 15:06:52 25 4
gpt4 key购买 nike

我有这段代码,我想将从 MKLocalSearch 获取的位置保存在一个数组中,以便稍后使用它们。你知道我该怎么做吗?

func searchForBarsAndRestaurants(searchFor: String){
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = typeOfPlace //or whatever you're searching for

request.region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300)


let search = MKLocalSearch(request: request)
search.start { response, error in
guard let response = response
else {
print("There was an error searching for: \(String(describing: request.naturalLanguageQuery)) error: \(String(describing: error))")
return
}

print(response.mapItems.count)
print("There are \(response.mapItems.count)" , searchFor)
for item in response.mapItems {
// You may be able to match the address to what the geoCode gives you
// or present the user with a list of options
print("\(String(describing: item.name))")
var totalDistances: Array<Double> = Array()
let distance = self.location.distance(from: item.placemark.location!)
totalDistances += [distance]
print("distance is " ,distance)
print(totalDistances.count)
}
}
}

最佳答案

当然,您只需要使用单例即可。

您想要的是使用全局变量。这是一个如何做到这一点的例子,w

let sharedNetworkManager = NetworkManager(baseURL: API.baseURL)

class NetworkManager {

// MARK: - Properties

let baseURL: URL

// Initialization

init(baseURL: URL) {
self.baseURL = baseURL
}

}

关于ios - 使用 swift 和 market 查找附近的酒吧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48309509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com