Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+6 votes

Using Swift, I tried:

let DODcomponents = endDate.calendar.components([.Day, .Month, .Year], fromDate: endDate.date)

Where endDate is the outlet for the UIDatepicker for the date of death. I get the error message "Ambiguous use of 'components'" but Xcode doesn't offer any solutions like it normally does when you have syntactically incorrect code.

Everything I've found online is either out of date, in Objective-C, or also doesn't work. This seems like a really simple thing to try and do, so I'm hoping for a simple solution

asked in CSC490_Spring2019 by (809 points)
edited by

2 Answers

+3 votes
 
Best answer

I don't know anything about Swift, but... I would imagine the UIDatePicker would allow you to get a Date object, and then you could get the individual components from that?

Maybe this tutorial will help?

http://www.globalnerdy.com/2016/08/18/how-to-work-with-dates-and-times-in-swift-3-part-1-dates-calendars-and-datecomponents/

answered by (17.9k points)
selected by
0

That's perfect, thank you

–1 vote

For IOS i'm not sure but it should like Android do, you have a get method to get the time you picked

answered ago by (2.2k points)
...