Skip to content

Instantly share code, notes, and snippets.

View intan1907's full-sized avatar
🏠
Working from home

Intan Nurjanah intan1907

🏠
Working from home
  • Bandung, Indonesia
  • 11:19 (UTC +07:00)
View GitHub Profile
@intan1907
intan1907 / HeartyRecipeWidget.swift
Created June 16, 2021 06:01
New StaticConfiguration for HeartyRecipeWidget
@main
struct HeartyRecipeWidget: Widget {
let kind: String = "HeartyRecipeWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
HeartyRecipeWidgetEntryView(entry: entry)
}
.configurationDisplayName("Hearty Recipe Widget")
.description("Display a widget with a random recipe that is updated every 1 hour.")
@intan1907
intan1907 / HeartyRecipeWidget.swift
Created June 16, 2021 05:51
New HeartyRecipeWidget struct
// ...
struct HeartyRecipeWidgetEntryView: View {
var entry: Provider.Entry
var body: some View {
HeartyRecipeWidgetView(recipe: entry.recipe)
}
}
@intan1907
intan1907 / HeartyRecipeWidget.swift
Last active June 16, 2021 05:53
New SimpleEntry
import WidgetKit
import SwiftUI
import HeartyRecipeHelper
// ...
struct SimpleEntry: TimelineEntry {
let date: Date
let recipe: RecipeBaseClass?
}
@intan1907
intan1907 / Data.swift
Created June 16, 2021 05:14
Function to Randomize Recipe
import Foundation
public var recipeData: [RecipeBaseClass]? = loadJsonFromFile()
// load dummy data from json file
func loadJsonFromFile(fileName: String = "Recipes") -> [RecipeBaseClass]? {
// ...
}
@intan1907
intan1907 / HeartyRecipeWidgetView.swift
Created June 16, 2021 05:05
Completed HeartyRecipeWidgetView
import Foundation
import SwiftUI
import WidgetKit
import HeartyRecipeHelper
struct HeartyRecipeWidgetView: View {
var recipe: RecipeBaseClass?
var body: some View {
ZStack(alignment: .top) {