Post

Replies

Boosts

Views

Activity

Custom Birthdate Picker Implementation
Hello! I am trying to make my own birthdate picker implementation where I want three wheels side-by-side in an HStack. Of course, the values inside these wheels depend on each other, for example, depending on the year, February different number of days, and depending on the month, there are different number of days. I tried making a model for this, but it's returning me the "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" error in the init() line. Could you please tell me what's wrong with this? The picker view: Section {               HStack {                 Picker("Year", selection: birthdateModel.$selectedYear) {                   ForEach(birthdateModel.years, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)                 Picker("Month", selection: birthdateModel.$selectedMonth) {                   ForEach(birthdateModel.months, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)                 Picker("Day", selection: birthdateModel.$selectedDay) {                   ForEach(birthdateModel.days, id: \.self) {                     Text(String($0))                   }                 }                 .pickerStyle(.wheel)               }             } Birthdate model: class BirthdateModel: Equatable, Hashable {       let monthWith30Days = ["Apr", "Jun", "Sep", "Nov"]   let monthWith31Days = ["Jan", "Mar", "May", "Jul", "Aug", "Oct", "Dec"]   var daysInFeb = 28   let years = 1900...Calendar.current.component(.year, from: Date())   let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]   var days = 1...31   var date = 0       let currentDate = Date()   let dateFormatter = DateFormatter()   let monthString = ""       @State var selectedYear: Int = 1900 {     didSet(year) {       if ((year % 4 == 0) && (year / 4 != 0)) {         daysInFeb = 29       }       self.changeDate()     }   }   @State var selectedMonth: String = "Jan" {     didSet(month) {       if monthWith31Days.contains(month) {         days = 1...31       }       else if monthWith30Days.contains(month) {         days = 1...30       }       else {         days = 1...daysInFeb       }       self.changeDate()     }   }   @State var selectedDay: Int = 1 {     didSet(day) {       self.changeDate()     }   }       init() {     self.dateFormatter.dateFormat = "Lll";     self.monthString = self.dateFormatter.string(from: self.currentDate);           self.selectedYear = Calendar.current.component(.year, from: Date())     self.selectedMonth = self.monthString     self.selectedDay = Calendar.current.component(.day, from: Date())     changeDate()   }       func hash(into hasher: inout Hasher) {     hasher.combine(date)   }       static func ==(lhs: BirthdateModel, rhs: BirthdateModel) -> Bool {     return lhs.date == rhs.date   }       func changeDate() {     self.date = (self.selectedYear * 10000) + ((self.months.firstIndex(where: {$0 == self.selectedMonth}) + 1) * 100) + self.selectedDay   }     }
1
0
439
Jan ’23
Taking user input in MapKit
Is there an easy way to take in user input through a tap gesture and place a marker in a Map using MapKit? I am not very experienced in SwiftUI. The only thing that comes to my mind is creating an overlay, detecting the tap position, converting that into map coordinates using map center and span, and then creating a MapPin for that. Only problem is, because of the overlay I can't pan or zoom the map. I can add drag gestures to the overlay and then pass the translation to map in the form of map center, but that's too much work. Is there any better way to do this?
2
0
1k
Dec ’21
My MapView crashes when I start filling out the address form
I am trying to build a Map View using MapKit which takes in user provided parameters such as locality, administrative area, etc., and when the user taps "submit", it should place a marker at the place, if it finds it on the map. However, even before I tap the button, once I tap out of one of the address fields, the app crashes with the following crash message: Thread 3: signal SIGABRT I don't understand this at all because I don't even tap the button which sends the address to LocationManager to convert it to coordinates in the first place. How does it crash when the MapKit functions aren't even called? I have tried using the same form with the same state objects and everything without the map on the screen, and it works just fine. So it has to do something with MapKit, right? Please help, I'm on a bit of a time crunch. MainView Part of LocationFormView LocationManager
1
0
475
Dec ’21