views:

44

answers:

2

How to create new NSDate object from [myUIDatePicker date] ?

+1  A: 

You don't need to create a new NSDate object, you can just use the one it gives you.

NSDate *chosenDate = myDatePicker.date;
jtbandes
I want to get multiple dates from the picker, so I think I need to create multiple object and then insert those dates in the NSMutableArray.
sza
You can just do `[array addObject:myDatePicker.date]` whenever you want to add a date.
jtbandes
But somehow the object I inserted is out of scope. My guess is myDatePicker.date will not be returned the new NSDate object every time...
sza
Yes, myDatePicker.date gives you the date it's set to. What do you mean it's out of scope? Can we see some code?
jtbandes
You probably didn't initialize the array with enough capacity via `arrayWithCapacity`
iWasRobbed
No, `arrayWithCapacity` is just a suggestion for the array, you can still add more objects.
jtbandes
+1 for using dot syntax correctly.
Abizern
+1  A: 

If you really need to create a new NSDate object, then you may call [[myUIDatePicker date] copy].

kovpas
There's no mutable NSDate, so there's really not a reason to do this..
jtbandes