Created
October 8, 2024 14:23
-
-
Save lucianoschillagi/98474577d01354ed040ad4721b55c9cd to your computer and use it in GitHub Desktop.
swiftui environment values → calendar (use case)
This file contains hidden or 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
| import SwiftUI | |
| struct CalendarView: View { | |
| @Environment(\.calendar) var calendar // Access the user's calendar environment value | |
| // Computed property to get the current date in the user's calendar | |
| var currentDateInUserCalendar: String { | |
| let formatter = DateFormatter() | |
| formatter.calendar = calendar // Use the user's calendar | |
| formatter.dateStyle = .full | |
| return formatter.string(from: Date()) | |
| } | |
| var body: some View { | |
| VStack(spacing: 20) { | |
| Text("Today's Date") | |
| .font(.largeTitle) | |
| // Display the current date formatted according to the user's calendar | |
| Text(currentDateInUserCalendar) | |
| .font(.title) | |
| .padding() | |
| .background(Color.blue) | |
| .foregroundColor(.white) | |
| .cornerRadius(10) | |
| } | |
| .padding() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment