Post

Replies

Boosts

Views

Activity

Pass a Timer through Controllers
I have an app that manages orders. It has a tab controller with three tabs, the second tab submits the order and the third tab shows all the ongoing orders once they are submitted. Each order generates an estimated time remaining for delivery. On the third tab, when showing the ongoing orders, there is a progress view which fills up as the time for delivery from the order elapses. How can I fire a timer on the second tab when the user submits the order, and keep the progress view on the third tab updated with such timer? I also wish for the user to be able to close the app and have the timer run in the background What is a possible workaround for this?
2
0
492
Jan ’22
Toggling between two date Pickers in a table view?
Hi, I'm going over the - Hotel Manzana - project in "Develop in Swift - Data Collections". The app is for the registration and room assignment for a hotel. I must include the Check In date and the Check out date for the which I'm using a date picker for both set in a 4 row section in a table view just like in the next image: When running the app the Date pickers must be hidden. And to activate one must press the check in or check out section just like this: Only one date picker must be shown at a time for which if I select one and the other is shown, then only the one I selected must be shown and the other must be hidden. However at the time of execution I can only open one Date Picker and close it one time. After that it won't show me neither of the date pickers again, no matter how much I press the check in or check out rows in the table view, they'll stay hidden after the first time I opened them... My code is as follows: class AddRegistrationTableViewController: UITableViewController {          @IBOutlet weak var firstNameTextField: UITextField!     @IBOutlet weak var lastNameTextField: UITextField!     @IBOutlet weak var emailTextField: UITextField!          @IBOutlet weak var checkInDateLabel: UILabel!     @IBOutlet weak var checkInDatePicker: UIDatePicker!     @IBOutlet weak var checkOutDateLabel: UILabel!     @IBOutlet weak var checkOutDatePicker: UIDatePicker!          var formattedDate: DateFormatter = {         let formattedDate = DateFormatter()         formattedDate.dateStyle = .medium                  return formattedDate     }()          let checkInDateLabelCellIndexPath = IndexPath(row: 0, section: 1)     let checkInDatePickerCellIndexPath = IndexPath(row: 1, section: 1)     let checkOutDateLabelCellIndexPath = IndexPath(row: 2, section: 1)     let checkOutDatePickerCellIndexPath = IndexPath(row: 3, section: 1)          var isCheckInDatePickerVisible: Bool = false {         didSet {             checkInDatePicker.isHidden = !isCheckInDatePickerVisible         }     }          var isCheckOutDatePickerVisible: Bool = false {         didSet {             checkOutDatePicker.isHidden = !isCheckOutDatePickerVisible         }     }          override func viewDidLoad() {         super.viewDidLoad()         // Uncomment the following line to preserve selection between presentations         // self.clearsSelectionOnViewWillAppear = false         // Uncomment the following line to display an Edit button in the navigation bar for this view controller.         // self.navigationItem.rightBarButtonItem = self.editButtonItem         let midnight = Calendar.current.startOfDay(for: Date())         checkInDatePicker.minimumDate = midnight         checkInDatePicker.date = midnight         updateDateViews()     }          func updateDateViews() {         checkOutDatePicker.minimumDate = Calendar.current.date(byAdding: .day, value: 1, to: checkInDatePicker.date)                  checkInDateLabel.text = formattedDate.string(from: checkInDatePicker.date)         checkOutDateLabel.text = formattedDate.string(from: checkOutDatePicker.date)     }          @IBAction func doneBarButtonTapped(_ sender: UIBarButtonItem) {         let firstName = firstNameTextField.text ?? ""         let lastName = lastNameTextField.text ?? ""         let email = emailTextField.text ?? ""         let checkInDate = checkInDatePicker.date         let checkOutDate = checkOutDatePicker.date                  print("firstName: \(firstName)")         print("lastName: \(lastName)")         print("email: \(email)")         print("checkInDate: \(checkInDate)")         print("checkOutDate: \(checkOutDate)")     }               @IBAction func datePickerValueChanged(_ sender: UIDatePicker) {         updateDateViews()     }          // MARK: - Table view data source     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {         switch indexPath {         case checkInDatePickerCellIndexPath where isCheckInDatePickerVisible == false:             return 0         case checkOutDatePickerCellIndexPath where isCheckOutDatePickerVisible == false:             return 0         default:             return UITableView.automaticDimension         }     }          override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         tableView.deselectRow(at: indexPath, animated: true)                  if indexPath == checkInDateLabelCellIndexPath && isCheckOutDatePickerVisible == false {             isCheckInDatePickerVisible.toggle()             if checkInDatePicker.isHidden == false {                 print("Check in date picker visible")             } else {                 print("Check in date picker not visible")             }         } else if indexPath == checkOutDateLabelCellIndexPath && isCheckInDatePickerVisible == false {             isCheckOutDatePickerVisible.toggle()             if checkOutDatePicker.isHidden == false {                 print("Check out date picker visible")             } else {                 print("Check out date picker not visible")             }         } else if indexPath == checkInDateLabelCellIndexPath || indexPath == checkOutDateLabelCellIndexPath {             isCheckInDatePickerVisible.toggle()             isCheckOutDatePickerVisible.toggle()         } else {             return         }         tableView.beginUpdates()         tableView.endUpdates()     } As you can see in tableView(_: didSelectRow) I added two conditional if statements to print to the console if either isCheckInDatePickerVisible and isCheckOutDatePicker are visible or not. Both of these do work and actually tell me that the value really is changing but my interface won't update and show me the date pickers more than one time .
1
0
1.4k
Nov ’21
Multiple Xcode versions on My Mac
Hi guys. I'm currently in the need of installing a lower Xcode version on my Mac. I've been doing some research and I know this is possible but I've still got some doubts about both the process and the possible outcomes. Currently I have Xcode 13 from the App Store and I need to install Xcode 12.5. I'm also currently on an M1 Mac with macOS Big Sur v11.6 My first doubt is, would installing a lower version of Xcode take up just as much space on my hard dive as the current version I already have installed? And if so, can I install the lower version on an external hard drive? Second, can having multiple Xcode versions installed cause unexpected behavior? How can I make this process in a safe and optimized way? Any guidance that you could provide me would be well appreciated
2
1
11k
Oct ’21
Guided Project: Apple Pie
Hi, I´m going through the "Develop in swift Fundamentals XCODE 12" course with the Apple Pie project. I'm having a bit of trouble with it. As long as I can see I can't find any errors in my code, so I was hoping any of you could help me out. For the record I'm currently on XCODE 13 Here is my code: As far as I know I've followed instructions correctly and even watched some videos who do it exactly the same. However when I run the app and click on one of the buttons, this happens: Can anyone explain to me why this is happening and how can I fix it?
4
0
3.3k
Oct ’21