Blog Archives

Getting the Tail Truncated Version of a String

Most of the iOS controls have the option to tail truncate a string with an ellipsis on the end. You can even get this same functionality when drawing a string yourself. However, there doesn’t seem to be a way to get the tail truncated version as an NSString.

iOS Developer Tips has a nice little category do get exactly that. It allows you to specify the width and font used and will return you the truncated version. Very handy! The code for it is located here.

Objective-C Quickie – Printing the name of a method

Getting the name of a method as a string is quite easy in objective-c.  This quickie is useful for logging, or in my case raising an exception if the method is not overridden by a subclass:

NSString *methodName = NSStringFromSelector(_cmd);

NSStringFromSelector is pretty straightforward, and _cmd is one of the two hidden parameters to every objective-c selector (along with self).