Я создаю приложение «История сегодняшнего дня» в iOS. Код следующий: [code]import Foundation import UIKit
final class HistoryAPICaller {
static let shared = HistoryAPICaller()
struct Constants { static let topHeadLinesURL = URL(string:"http://history.muffinlabs.com/date/6/3")
static let searchUrlString = "http://history.muffinlabs.com/date/6/3" }
private init() {}
public func getTopStories(completion: @escaping (Result) -> Void) {
guard let html = Constants.topHeadLinesURL else { return }
let task = URLSession.shared.dataTask(with: html) { data, _, error in if let error = error { completion(.failure(error)) } else if let data = data { do { let result = try JSONDecoder().decode(HistoryAPIResponse.self, from: data)
let urltring = Constants.searchUrlString + query guard let html = URL(string:urltring) else { return }
let task = URLSession.shared.dataTask(with: html) { data, _, error in
if let error = error { completion ( .failure(error)) } else if let data = data { do { let result = try JSONDecoder().decode(HistoryAPIResponse.self, from: data)
struct HistoryAPIResponse: Codable { let data: HistoryDataAPIResponse }
struct HistoryDataAPIResponse: Codable { let Events: [Events] }
struct Events: Codable { let year: String let text: String let html: String let no_year_html: String let links: [Links] }
struct Links: Codable { let link: String } [/code] Теперь я хочу добавить в код функцию текущей даты, чтобы вместо постоянного отображения исторического события 3 июня "http://history.muffinlabs.com/ date/6/3", это будет что-то вроде "http://history.muffinlabs.com/date/(currentMonth)/(currentDay)" Любой помощь будет принята с благодарностью.