ios - 'Int' is not identical to 'String' - Swift -


In this function I'm trying to get data from Uaidet drink and have it to subtract 5. For example, if UIDatePicker said 7:15 AM it would be subtracted from hour and at 2:15. The revised code would give where I own label does not work on the line, the error says 'int' 'string' is not the same work to address the original version where it works Whatever date I put in the date selector, the user chose this date, then 7:15 AM shows it appears at 7:15 pm without decreasing anything.

Hook had dates with the storyboard picture

  @Iboutlet weak Wardetdet Picture: Uaidit picture!  

Without .toInt () original code

  event handler (this: UIDatePicker) {var timeFormatter = NSDateFormatter () timeFormatter.timeStyle = NSDateFormatterStyle.ShortStyle bridesmaid strDate = timeFormatter.stringFromDate (theDatePicker.date) hoursLeftLabel.text = strDate}  

Revised code

  function handler (this: UIDatePicker) {var timeFormatter = NSDateFormatter () timeFormatter.timeStyle = NSDateFormatterStyle.ShortStyle on intDate = timeFormatter.stringFromDate (theDatePicker.date) .toInt () hoursLeftLabel.text = intDate}  

If you need any questions or an explanation below

attempt Please do comment below please use:

  hoursLeftLabel.text = "\ (intDate)"  

This should work, because you have a string I Create Nt date

The error is not similar to the int string, which means that you are crossing an int where a string is required. The error can actually be more accurate as the wrong type or something like this

EDIT: I recommend you calculate this kind of date:

  Let newDate = theTatePicker .date.dateByAddingTimeInterval (-5 * 60 * 60) // - 5 hours // Now you can display your date like this: hoursLeftLabel.text = timeFormatter.stringFromDate (newDate)  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -