Ready to Level-Up?

This just in! If your rusty iOS skills could use some refining, or if you're just starting out and you want to level-up fast, consider signing up for our upcoming iOS Screencasts

New from iOS Rocket Surgery Swift Video Tutorials: The rapidly evolving Apple-iOS ecosystem has just been thrown into tumult with the recent introduction of the Swift Programming Language. Are you ready to finally try iOS development? Are you needing to switch from Objective-C to Swift? Sign up today for our free video courses!
(By the dear folks at Swift Tutorial Videos, a sister company)

Thursday, December 19, 2013

iOS Get Class Name for Object

So, you have an object for which you would like to know the class name, right?

NSObjects all come with a class accessor method which you can call to determine the type of class your object is, whether you made the object yourself (extending NSObject or some inheritor from NSObject), or whether you're using an out-of-the-box object like NSString, they all respond to the "class" method.

Here's an example:


  NSString *myObject = @"Just a test!";
  
  Class theClass = [myObject class];


But, alas, we're not quite done, because you wanted to get the NAME the class... I didn't forget, see? If you have a Class object now, you can get the class name like so:



  NSString *className = NSStringFromClass(theClass);



Hopefully that gets you where you need to be, see you next time! 

Oh, and if you're still here, we'd love it if you gave us a +1 out of the kindness of your heart.




About Me

Easy NSDateFormatter Tool

Save yourself some time in formatting your NSDates to NSStrings, and use the Blind NSDate app, which you can download from iTunes. There's also a website where you can format your NSDates: http://www.blindnsdate.com

Popular Posts

Designed By Seo Blogger Templates