Post

Replies

Boosts

Views

Activity

Reply to Showing Decimal value
Unfortunately, the String interpolation of LocalizedStringKey using specifier: requires the value conform to _FormatSpecifiable, to which Decimal does not. See LocalizedStringKey.StringInterpolation. String interpolation of String does not support interpolation using specifier:. See DefaultStringInterpolation. You can use a String interpolation of LocalizedStringKey using formatter: with value of NSDecimalNumber: struct ContentView: View { let myFormatter: NumberFormatter = { let nf = NumberFormatter() nf.maximumFractionDigits = 2 nf.minimumFractionDigits = 2 return nf }() @State var myVariable: Decimal = Decimal(string: "66.67")! var body: some View { Text("\(myVariable as NSDecimalNumber, formatter: myFormatter)") } } If Decimal operation is not important for your app, using Double (which conforms to _FormatSpecifiable) might be a good option. Or you can customize the behavior of String interpolation of LocalizedStringKey, but I'm not sure if it would be a good option.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to MatchedGeometryEffect SwiftUI
I have not played with matchedGeometryEffect yet, so read the followings as as far as I tried things. There may be other better ways. Text, is duplicated during the transition You have two Texts, and with using matchedGeometryEffect, they both are animated. Applying matchedGeometryEffect after frame is specified, the positions of the two in animation are different. Please try moving matchedGeometryEffect before frame. when I press again to get it back to its original position, no animation takes place Seems some sort of symmetry is needed to trigger animation when you set numberViewModel.tapped to false. Please try something like this: struct NumberView: View { @ObservedObject var numberViewModel: NumberViewModel var animation: Namespace.ID var number: Number var body: some View{ GroupBox{ if numberViewModel.selected.number != number.number { Text("\(number.number)") .font(.largeTitle) .matchedGeometryEffect(id: number.number, in: animation) //<- .frame(width: 100, height: 100, alignment: .center) } } } } struct NumberTappedView: View { var animation: Namespace.ID @ObservedObject var numberViewModel: NumberViewModel var body: some View{ GroupBox { if numberViewModel.tapped { //<- Text("\(numberViewModel.selected.number)") .font(.largeTitle) .matchedGeometryEffect(id: numberViewModel.selected.number, in: animation) //<- .frame(width: 200, height: 200, alignment: .center) } //<- } } } Or you would prefer this version of NumberTappedView: struct NumberTappedView3: View { var animation: Namespace.ID @ObservedObject var numberViewModel: NumberViewModel var body: some View{ GroupBox { if numberViewModel.tapped { ZStack { ForEach(numbers) { number in if numberViewModel.selected.number == number.number { Text("\(numberViewModel.selected.number)") .font(.largeTitle) .matchedGeometryEffect(id: numberViewModel.selected.number, in: animation) .frame(width: 200, height: 200, alignment: .center) } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to UIImage.init - imageLiteralResourceName crashing during App review
So, I assume you use some code like this: func getCurrrentDayNumber() -> String { let currentDateTime = Date(); let formatter = DateFormatter(); formatter.timeStyle = .none; formatter.dateStyle = .long; let dateTimeString = formatter.string(from: currentDateTime); var dayNumber = dateTimeString.split(separator: " "); dayNumber = dayNumber[1].split(separator: ","); return String(dayNumber[0]); } Frankly saying, this is a super bad implementation to get the day number (1...31). I do not know which languages your app would support, but your getCurrrentDayNumber() returns August when region is set to United Kingdom even when Language is set to en. I believe that would cause the error you described. Please try something like this: func getCurrrentDayNumber() -> String { let currentDateTime = Date() var gregorianCalendar = Calendar(identifier: .gregorian) gregorianCalendar.timeZone = TimeZone.current let dateComponents = gregorianCalendar.dateComponents([.day], from: currentDateTime) return String(dateComponents.day!) } Generally, you should better not rely on the String generated by DateFormatter.Style.long.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Practical Use of Combine's Subject
In your viewDidLoad() you declare a local variable cancellable, which is disposed at the end of the scope. In your case, it is at the end of viewDidLoad. Please try something like this: override func viewDidLoad() { super.viewDidLoad() self.cancellable = currentValueSubject .sink { value in print("New value: \(value)") } currentValueSubject.send(5) currentValueSubject.send(10) //currentValueSubject.send(completion: .finished) currentValueSubject.send(15) //cancellable.cancel() }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Xcode 12.5 StackView & Constraints - Where is the Attributes Inspector -> Distribution Menu?
As far as I can see, you have not put a UIStackView on your storyboard. The view may be named as stackView, but is not a UIStackView. It's just a UIView. If you had successfully put a UIStackView, it would be shown with a sandwich icon: I am not sure if you have mistaken or your Xcode is malfunctioning, but you should better remove your Stack View and go back to the part where tutorial shows how to put UIStackView.
Aug ’21
Reply to How to get the UIViewController instance for displaying dialog when the app starts up?
how can I get a UIViewController instance when the app starts, such that I can pass it into the SDK function for dialog display? If it is not possible to do it in AppDelegate.swift, can it be done some where else? If your project have an automatically generated SceneDelegate.swift, you may do it in it. But it is hard to say if it really would work or not, without knowing what showConsentDialog does and how your project is organized.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21