Don’t Forget about Object-Oriented Programming!

Now you know how to define a structure to store a date, and you’ve written various routines to manipulate that date structure. But what about object-oriented programming? Shouldn’t you have made a class called Date instead and then developed methods to work with a Date object? Wouldn’t that be a better approach? Well, yes. Hopefully, that entered your mind when we discussed storing dates in your program.

Certainly, if you have to work with a lot of dates in your programs, defining a class and methods to work with dates is a better approach. In fact, the Foundation framework has a couple of classes, called NSDate and NSCalendarDate, defined for such purposes. We leave it as an exercise for you to ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.