Clicky

iOS Dev Nugget 123 Using dynamicType in Swift

.

Need to run a code review on your codebase? Hire me

A quick tip this week. If you have been using the object_getClassName() function when using Objective C to print out the class of an object, you can use dynamicType to do it in Swift:

var s = "abc"
println("class name: \(s.dynamicType)")

In addition, you can use dynamicType to create a new instance of the class:

var type = s.dynamicType
var anotherInstance = type() //Like String()


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues