Posts

Post not yet marked as solved
0 Replies
386 Views
A puzzling phenomenon occurs in obtaining the week number. Please see the attached source. In Step 0, the correct week number can be obtained according to ISO8601. In Step 1, by changing minimumDaysInFirstWeek, a new (correct) week number can be obtained. In Step 2, if I re-set the firstWeekday, for some reason the week number reverts back to the original, even though the value has not been changed. Shouldn't Step2 return 1 for both weekOfMonth and weekOfYear? I have verified this with XCode 13.4 playground. Thanks in advance. import Foundation var calendar = Calendar(identifier: .iso8601) let date = calendar.date(from: DateComponents(year: 2022, month: 1, day: 1)) print("*** Step 0 ***") print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") print("\n*** Step 1 ***") calendar.minimumDaysInFirstWeek = 1 print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") print("\n*** Step 2 ***") calendar.firstWeekday = 2 print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") Result *** Step 0 *** firstWeekday : 2 minimumDaysInFirstWeek : 4 weekOfMonth : 0 weekOfYear : 52 *** Step 1 *** firstWeekday : 2 minimumDaysInFirstWeek : 1 weekOfMonth : 1 weekOfYear : 1 *** Step 2 *** firstWeekday : 2 minimumDaysInFirstWeek : 1 weekOfMonth : 0 weekOfYear : 52
Posted Last updated
.
Post marked as solved
5 Replies
1.2k Views
When I run the following code, it works fine on iOS 4.4 and up, but on iOS 4.5, the alert does not show up and the following log is output. 2021-05-08 18:21:34.680280+0900 SampleProject12.5[2534:139985] [Presentation] Attempt to present SwiftUI.PlatformAlertController: 0x7ff27200ce00 on _TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS14NoStyleContext: 0x7ff26f825000 (from _TtGC7SwiftUIP13$7fff5695965428DestinationHostingControllerVS7AnyView: 0x7ff271c06180) whose view is not in the window hierarchy. import SwiftUI struct ContentView: View {   var body: some View {     NavigationView {       List {         NavigationLink(destination: NextView()) {           Text("Next View")         }       }     }   } } struct NextView: View {   @State private var showingAlert = false       var body: some View {     Button("Show Alert") {       showingAlert = true     }     .alert(isPresented: $showingAlert) {       Alert(title: Text("Alert!"))     }     .onAppear {       showingAlert = true     }   } }
Posted Last updated
.
Post marked as solved
1 Replies
673 Views
When I run the following code, once I open and close the sheet, the toolbar buttons become unusable. When there is only one button, there is no problem, but when there are two buttons, this phenomenon occurs. Is there a workaround? The environment is Xcode: 12.5, iOS: 14.5. import SwiftUI struct ContentView: View {   @State private var showingSheet = false       var body: some View {     NavigationView {       Text("1st View")         .toolbar {           ToolbarItem(placement: .navigationBarTrailing) {             HStack {               Button("Button1") {                 showingSheet = true               }               Button("Button2") {                 showingSheet = true               }             }           }         }         .sheet(isPresented: $showingSheet) {           Sheet()         }     }   } } struct Sheet: View {   @Environment(\.presentationMode) var presentationMode   var body: some View {     Button("close sheet") {       presentationMode.wrappedValue.dismiss()     }   } }
Posted Last updated
.