gpt4 book ai didi

ios - 将时间变量添加到过滤器(Swift)

转载 作者:行者123 更新时间:2023-11-30 12:00:49 24 4
gpt4 key购买 nike

我正在使用 Google Places API,在 VC 中我想显示附近的地点,我为要下载的地点创建了一个过滤器

if response.status == "OK" {
if let placesDownloaded = response.places {
var number = numberPlaces / (categories?.count)!
number = number == 0 ? 1 : number

let firstPlace = placesDownloaded.prefix(1)

var isRestaurant = false


for place in firstPlace {
for type in place.types! {
if (type.lowercased() == "restaurant") {
isRestaurant = true
}
}
}
if(isRestaurant) {
number = 1
}

places.append(contentsOf: placesDownloaded.prefix(number))
}

现在我想向此过滤器添加“时间”变量(例如 if (type.lowercased() == "restaurant"&& 用户位置的时间是 12 点){} 等)但我真的不知道该怎么做,有人能给我举个例子,说明如何添加时间变量并在这个过滤器中使用它吗?

最佳答案

您可以通过使用 NSDateformatter 来实现它,如下所示,

let dateFormatter = NSDateFormatter()
dateFormatter.timezone = TimeZone.current
dateFormatter.dateFormat = "hh:mm"
print(dateFormatter.stringFromDate(NSDate()))

关于ios - 将时间变量添加到过滤器(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47263085/

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