Snippets Collections
@IBOutlet weak var dayPicker: UIPickerView!
     
var pickerData: [Int]!

  viewDidLoad(){
  setDayPicker()
  dayPicker.delegate = self
  dayPicker.dataSource = self
}
  
//MARK: - Day Picker

extension PostRequestViewController : UIPickerViewDelegate, UIPickerViewDataSource {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        print("\(pickerData[row])")
            return "\(pickerData[row])"
        }
    
    func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
        let attributedString = NSAttributedString(string: String(pickerData[row]), attributes: [NSAttributedString.Key.foregroundColor : pickerView.hexStringToUIColor(hex: "FEDA22")])
        return attributedString
    }
    
    func setDayPicker () {
        let minDay = 1
              let maxDay = 90
              pickerData = Array(stride(from: minDay, to: maxDay + 1, by: 1))
    }
}
func isDayEnded(recent: Date, previous: Date) -> Bool {
    let day:Int = Calendar.current.dateComponents([.day], from: previous, to: recent).day ?? 0
    if day >= 1 {
        return true
    } else {
        return false
    }
}
let previous = NSDate(timeIntervalSince1970: 1645601459)
let recent = NSDate(timeIntervalSince1970:   1648020659)
let dayEnded = isDayEnded(recent: recent as Date, previous: previous as Date)
print("Day = \(dayEnded)")
star

Mon Jun 13 2022 06:32:37 GMT+0000 (UTC)

#ios #swift #day #daypicker #picker
star

Thu Feb 24 2022 07:51:11 GMT+0000 (UTC)

#ios #swift #day #date #difference

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension