Post

Replies

Boosts

Views

Activity

Reply to DatePicker
Here is a simple view with 2 DatePickers: import SwiftUI extension Date {     var justDate: String {         let dateFormatter = DateFormatter()         dateFormatter.dateStyle = .long         dateFormatter.timeStyle = .none         return dateFormatter.string(from: self)     } } struct ContentView: View {     @State private var start = Date()     @State private var end = Date()     var body: some View {         List {             Section(header: Text("Select Dates")) {                 DatePicker("Start date", selection: $start, displayedComponents: [.date])                 DatePicker("End date", selection: $end, displayedComponents: [.date])             }             Section(header: Text("Date Values")) {                 Text("Start: \(start.justDate)")                 Text("End: \(end.justDate)")             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Apr ’22
Reply to Why are types defined with extension?
Thanks Claude, I re-read the section on Extensions and this is what it says at the top of that section: Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling). So Apple obviously has the source code, that's not why they're doing it. I see how each protocol is a separate extension, that makes sense to me too. But I also see that each operator is also an extension. How does that help?
Jul ’20