Converting an NSDate to NSString can sometimes be not as simple as one would hope. NSharpDate is a NSDate category that can help you with this. It adds easy to use methods and properties to the NSDate object.
Example of a method
To get a NSString from a NSDate you need to use a NSDateFormatter. The following code is how you could do it without NSharpDate which would produce a string looking like this: 5/27/12 if the IOS device locale is US, or like this if the locale is Sweden: 2012-05-27.
With NSharpDate you only need one line of code to do this:
This is only one of the five methods added to NSDate, to see the other methods head over to the NSharpDate site.
Example of a property
To get the day of week from an nsdate you would use the following code without NSharpDate. This would give you a string like “Sunday” or “Söndag:
To get the same result with NSharpDate you do the following:
There are a few more properties added to NSDate which you can find here.
Download and setup
there are only three steps involved to get started with NSharpDate.
If you find a bug or want to add a feature to the project you are very welcome to add this code to the category. You can head over to github to fork the project and send me a pull request when you are done.