Created
June 30, 2020 15:32
-
-
Save arthurpalves/b1c16bcb3a7667ee243a926120390eb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Provider: TimelineProvider { | |
public typealias Entry = AccountEntry | |
let viewModel = ViewModel() | |
public func snapshot(with context: Context, completion: @escaping (AccountEntry) -> ()) { | |
let entry = SimpleEntry(date: Date(), product: previewProduct, maskSensitiveData: false) | |
completion(entry) | |
} | |
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
let currentDate = Date() | |
let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)! | |
viewModel.fetchProducts() { products in | |
guard let mainProduct = products.first(where: { $0.type == .main }) else { return } | |
let entry = AccountEntry(date: currentDate, product: mainProduct) | |
let timeline = Timeline(entries: [entry], policy: .after(refreshDate)) | |
completion(timeline) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment