0

I'm new to Xcode and I'm creating a rather simple Mac App with Xcode that has a DatePicker which will save the selection to a Coredata model.

While in Interface Builder, under that DatePicker's attributes, I can set a minimum date, maximum date and default date to show. However, I would like the default date shown to be tagged to the current time so that my user does not need to choose the date value unless it is a back dated entry.

I opened up the .xib file and found the following code that can change the default date shown:

<object class="NSDate" key="NSContents">
    <double key="NS.time">354974400</double>
</object>

The default date can be changed by altering the value within the double key="NS.time" and /double tags. And it also seems like this value is in the number of seconds since 1970.

I have tried:

NSDate *today = [NSDate date];

I understand that I'll still need to convert that to a double value that is in the number of seconds since 1970.

So the question is, how can I change the current date to a value that I can parse it in so that the default date shown will always be the current date?

C4 - Travis
  • 4,502
  • 4
  • 31
  • 56

1 Answers1

2

When the view loads, call -setDateValue: on the NSDatePicker.

Morrowless
  • 6,856
  • 11
  • 51
  • 81
  • Hi Plenulune, Thanks for the reply, I've only just started on Xcode and still figuring my way around it. Would this line of code be in the same .xib file? If it is so where and how do I add it? – user1363643 Apr 29 '12 at 02:56
  • Hi, you would not do this in the xib file, but in the view controller containing the date picker. see NSViewController -initWithNibName:bundle: – Morrowless Apr 29 '12 at 03:16