Coding Explorer Blog

Exploring how to code for iOS in Swift and Objective-C

  • Home
  • Apps
  • About
  • Contact

Archives for March 2014

Displaying a human readable NSDate

Last updated on July 23, 2014

Much like Casey Liss of the Accidental Tech Podcast, talked about recently on the Debug podcast, I came from C# before I started working on Objective-C.  One frustration he had originally with Objective-C was with getting a human readable date out of an NSDate object, when it was so easy to just type someDateTime.toString() in C#.  That was also one of my earliest frustrations, and I thought it would be nice to share with my readers.

In C#, you store dates in objects of the type DateTime.  The Objective-C equivalent of this is NSDate.  In C#, you can simply create a specific date date with:

DateTime someDate = new DateTime(2013, 12, 31);

And that would make a DateTime object for December 31, 2013.  There are a few ways to do this in Objective-C, and while they are not as easy, they do make it much more friendly to using non-Gregorian calendar systems.  NSDateFormatter can both format an NSDate into a string (more on this later), but it can also attempt to parse a string with date data.  The more exact way though, would probably be to use NSDateComponents.

[Read more…]

Filed Under: Syntax

Property Attributes in Objective-C

Last updated on July 23, 2014

In my previous articles, you’ve probably seen properties used many times. In this article I wanted to write down (in one place) and explain the attributes that can be used on them. At least in this context, “attributes” refers to the modifiers to the property (usually strong and nonatomic in my previous articles). I have covered those two a little bit in a previous article, but I wanted to list them all here.

 Valid Property Attributes

  • atomic
  • nonatomic
  • strong
  • weak
  • readwrite
  • readonly
  • getter=
  • setter=
  • copy
  • assign
  • retain
  • unsafe_unretained

[Read more…]

Filed Under: Syntax

Objective-C Categories

Last updated on July 23, 2014

Have you ever wished you could add a method to an existing class that you don’t have the code for?

Well, now you can, with categories.

Categories let you extend an existing class with whatever method you deem fit.  It is pretty useful to add helper methods to other classes that help parse the date in a way the class make perhaps did not intend.  You can also use it to split up your own classes so that if you have some big omni-class that does several things, you can opt in to just the parts you want by only including those categories.

[Read more…]

Filed Under: Syntax

Subscribe to the Coding Explorer Newsletter

* indicates required

Follow Us

Facebooktwitterrss

Recent Posts

  • Error Handling in Swift
  • Creating and Modifying a URL in your Swift App
  • Watch Connectivity in Swift — Application Context
  • watchOS Hello World App in Swift
  • API Availability Checking in Swift

Categories

  • Class Reference
  • General
  • Interface Builder
  • My Apps
  • Objective-C
  • Swift
  • Syntax
  • Tutorial
  • Uncategorized

Archives

  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • November 2013
  • September 2013
  • August 2013
  • July 2013
  • Terms Of Use
  • Privacy Policy
  • Affiliate Disclaimer

Subscribe to the Coding Explorer Newsletter

* indicates required

Copyright © 2025 Wayne Media LLC · Powered by Genesis Framework · WordPress