NSStringFromClass in Swift is Here!
One of the first things I immediately noticed was missing from Swift was the NSStringFromClass replacement. I like to use the class name for my TableViewCell identifiers, and then just NSStringFromClass to dequeue the cells to avoid spelling issues.
In Swift, I would write an ugly extension to do that as seen in this StackOverflow answer:
1 2 3 4 5 6 7 8 9 |
public extension NSObject{ public class var nameOfClass: String{ return NSStringFromClass(self).componentsSeparatedByString(".").last! } public var nameOfClass: String{ return NSStringFromClass(self.dynamicType).componentsSeparatedByString(".").last! } } |
Not sure when it happened, but I was extremely to see a more native solution in @aligatr’s blog post!
1 2 |
// This now works!!! String(MyTableViewCell) |
I tried it out myself just to be sure and it actually works!!

Custom BlueTableViewCell
1 2 3 4 5 6 7 8 |
// BlueTableViewController override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // the cell gets dequeued properly!!! let cell = tableView.dequeueReusableCellWithIdentifier(String(BlueTableViewCell), forIndexPath: indexPath) return cell } |
Super excited I don’t have to use the extension anymore!