Skip to content

Instantly share code, notes, and snippets.

View velotiotech's full-sized avatar

Velotio Technologies velotiotech

View GitHub Profile
#include <stdio.h>
int main() {
char c = 'D';
char *cp = &c;
int *ip = (int*)cp;
*ip = 0x64567842;
printf("%c\n", c);
return 0;
}
struct Provider: TimelineProvider {
// Provides a placeholder entry while the widget is loading.
func placeholder(in context: Context) -> DayEntry {
DayEntry(date: Date(), configuration: ConfigurationIntent())
}
// Provides a snapshot of the widget's current state.
func getSnapshot(in context: Context, completion: @escaping (DayEntry) -> ()) {
let entry = DayEntry(date: Date(), configuration: ConfigurationIntent())
completion(entry)
struct Provider: TimelineProvider {
// Provides a placeholder entry while the widget is loading.
func placeholder(in context: Context) -> DayEntry {
DayEntry(date: Date(), configuration: ConfigurationIntent())
}
// Provides a snapshot of the widget's current state.
func getSnapshot(in context: Context, completion: @escaping (DayEntry) -> ()) {
let entry = DayEntry(date: Date(), configuration: ConfigurationIntent())
completion(entry)
import WidgetKit
import SwiftUI
@main
struct MonthlyWidgetBundle: WidgetBundle {
var body: some Widget {
MonthlyHolidayWidget()
MonthlyWidgetLiveActivity()
}
}
struct MonthConfig {
let backgroundColor: Color // Background color for the month display
let dateText: String // Text describing specific dates or holidays in the month
let weekdayTextColor: Color // Text color for weekdays
let dayTextColor: Color // Text color for days of the month
let month: String // Name of the month
/// Determines and returns the configuration (MonthConfig) based on the given date.
///
/// - Parameter date: The date used to determine the month configuration.
extension Date {
// Computed property to get the weekday in a wide format (e.g., "Monday")
var weekDayDisplayFormat: String {
self.formatted(.dateTime.weekday(.wide))
}
// Computed property to get the day of the month (e.g., "22")
var dayDisplayFormat: String {
formatted(.dateTime.day())
}
struct MonthlyHolidayWidget_Previews: PreviewProvider {
static var previews: some View {
// Provide a preview of the MonthlyHolidayWidgetEntryView for the widget gallery
MonthlyHolidayWidgetEntryView(entry: DayEntry(date: dateToDisplay(month: 12, day: 22), configuration: ConfigurationIntent()))
.previewContext(WidgetPreviewContext(family: .systemLarge))
}
// Helper function to create a date for the given month and day in the year 2024
static func dateToDisplay(month: Int, day: Int) -> Date {
let components = DateComponents(calendar: Calendar.current,
struct MonthlyHolidayWidget_Previews: PreviewProvider {
static var previews: some View {
// Provide a preview of the MonthlyHolidayWidgetEntryView for the widget gallery
MonthlyHolidayWidgetEntryView(entry: DayEntry(date: dateToDisplay(month: 12, day: 22), configuration: ConfigurationIntent()))
.previewContext(WidgetPreviewContext(family: .systemLarge))
}
// Helper function to create a date for the given month and day in the year 2024
static func dateToDisplay(month: Int, day: Int) -> Date {
let components = DateComponents(calendar: Calendar.current,
struct MonthlyHolidayWidget: Widget {
let kind: String = "MonthlyHolidaysWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
MonthlyHolidayWidgetEntryView(entry: entry)
}
.configurationDisplayName("Monthly style widget") // Display name for the widget in the widget gallery
.description("The date of the widget changes based on holidays of month.") // Description of the widget's functionality
.supportedFamilies([.systemLarge]) // Specify the widget size supported (large in this case)
struct MonthlyHolidayWidgetEntryView: View {
var entry: DayEntry
var config: MonthConfig
// Custom initializer to configure the view based on the entry's date
init(entry: DayEntry) {
self.entry = entry
self.config = MonthConfig.determineConfig(from: entry.date)
}