Post

Replies

Boosts

Views

Activity

Date not fully localized with Date.FormatStyle
Is there a way using Date.FormatStyle to make the numbers also show in Hebrew the same way DateFormatter does? For some reason using Date.FormatStyle doesn't seem to have the ability to show the numbers locally. Here's some sample code, you can see that using DateFormatter the locale is respected and it displays properly but using Date.FormatStyle the numbers are still regular numbers. Update: Here's a modified version of DateFormatter. The goal is using Date.FormatStyle and getting the same result as DateFormatter import SwiftUI struct ContentView: View { let date = Date.now var body: some View { List{ Text(date.formatted(formatStyle.attributed)) .environment(\.locale, Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel)) .environment(\.calendar, Calendar(identifier: .hebrew)) Text(date, format: formattttttt) .environment(\.locale, Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel)) .environment(\.calendar, Calendar(identifier: .hebrew)) Text(dateFormatted(date: date)) } } func dateFormatted(date: Date) -> String{ let dateFormatter = DateFormatter() dateFormatter.calendar = Calendar(identifier: .hebrew) dateFormatter.locale = Locale(identifier: "he") dateFormatter.dateStyle = .full return dateFormatter.string(from: date) } let formatStyle = Date.FormatStyle( date: .complete, time: .omitted, locale: Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel), calendar: Calendar(identifier: .hebrew) ) let formattttttt = Date.FormatStyle( date: .complete, time: .omitted, locale: Locale(identifier: "he"), calendar: Calendar(identifier: .hebrew)).locale(Locale(identifier: "he")) }
2
0
1.1k
Jul ’23
Numbers not fully localized with Formatted(.number.locale())
I'm trying to display an Int in Hebrew. so for example 123 should display אבג 1 = א 2 = ב 3 = ג I have tried specifying the locale based on a the answer to a different post of mine where the solution was to specify the numbering system in the locale Locale(identifier: "he-IL@numbers=hebr") print(123.formatted(.number.locale(Locale(identifier: "en@numbers=hebr")))) // Output: 123 When setting the same locale for dates it formats properly with Hebrew numbers. However if I do Arabic instead of Hebrew the numbers display properly in arabic the result for this is `` print(123.formatted(.number.locale(Locale(identifier: "en@numbers=Arab")))) // Output: ١٢٣ Below is the code I've tried running in a playground: This is the code I ran in the playground
3
0
855
Jan ’24
Date.FormatStyle.Symbol.Hour defaultDigits shows leading zero if amPM is set to .omitted
I'm trying to format a date to show the current time with the least amount of digits as possible. Using Date.FormatStyle and adding .hour() is the closest I can get. See the code below ↓ var formatStyle = Date.FormatStyle() var hourMinute: Date.FormatStyle{ formatStyle .hour() .minute() } // Output 3:15 PM var hourMinuteDefaultDigits: Date.FormatStyle{ formatStyle .hour(.defaultDigits(amPM: .omitted)) .minute() } // Output 03:15 My goal is to output 3:15 without the amPm but that doesn't seem possible using Date.FormatStyle. Based on the documentation this is the function signature func hour(_ format: Date.FormatStyle.Symbol.Hour = .defaultDigits(amPM: .abbreviated)) -> Date.FormatStyle // Output 3:15 PM For some reason if I put .omitted for the amPM then defaultDigits and twoDigits return the same 2 digits for the hour
1
0
556
Aug ’24
How to add a reoccurring Hebrew Event to a calendar.
Currently Apple has their own calendar called Birthdays which takes the birthdays from contacts and makes it as a regular calendar event along with the birthday number, they even do this for Hebrew Birthdays. I have tried (unsuccessfully thus far) to take the same concept and create a calendar for reoccurring events on a specific date in the Hebrew Calendar. An example of this would be Yahrtzeits, which is observed on the Hebrew date each year after a person dies. I want to add it to the system calendars like how Apple does it this way it can be used with any app not just my own. Currently there isn't a way to specify the calendar (like Calendar(identifier: .hebrew) or even make a custom EKRecurrenceRule, also from some of the debugging of the Birthdays calendar, it seems that the date saved is the Gregorian date and that theres some internal calculations happening. Is there a way to add reoccurring Hebrew Events or do I need to reinvent the wheel?
1
0
399
Nov ’24
UNNotificationRequest set timestamp to a relative time
The system calendar when showing a calendar event shows a relative timestamp on the notification versus all other apps which have a timestamp of when the notification was sent. Is there a way to set the timestamp to be relative? I am currently working on a calendar app and we should be able to use the same system that apple uses for its own calendar. Post about this on stack overflow from someone else a few years ago
1
0
304
Mar ’25
How to disable scrollToTop when clicking on selected tab
I currently have a SwiftUI TabView that has 5 Tab's. The first tab has a UIScrollView in a UIViewRepresentible with scrollView.scrollsToTop = false and that works fine for when the user hits the navigation bar, however if the user taps the first tab when it is already selected my UIScrollView scrolls to top. My UIScrollView is essentially 5 views, a center view, top, bottom, right, and left view. All views except for the center are offscreen but available for the user to scroll horizontal or vertical (and the respective views get updated based on the new center view). The issue I have is that clicking the first tab when its already selected, sets the content offset (for the y axis) to 0, which messes me up 2x, first it scrolls up but since its not really scrolling the right, left, and upper views dont exist, which makes the user think it can't be scrolled or it's broken. For now I subclassed UIScrollView like this class NoScrollToTopScrollView: UIScrollView { override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) { if contentOffset.y == .zero { // Ignore SwiftUI’s re-tap scroll-to-top return } super.setContentOffset(contentOffset, animated: animated) } } which seems to work, but I'm just wondering if there is a better way to do this, or maybe a way to disable SwiftUI Tab from doing its default action which can help with a SwiftUI ScrollView as well?
0
0
115
Sep ’25
How to add blur around the Tab bar in iOS 26
I have a TabView and in one of the tabs I have a horizontal ScrollView that uses .scrollTargetBehavior(.paging) in each of those pages I have a List, but the bottom of the list around the Tab bar doesnt get blurred, if I remove the horizontal scrollview and just have a list it blurs fine. So I want to know how I can manually add the blur when using the horizontal scrollview
1
0
147
Sep ’25