Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 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 (1 point)
edited by

2 Answers

+4 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 (3.5k points)
selected by
0

That's perfect, thank you

0 votes

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

answered by (1 point)
...