Observations, stories, projects, photos.
In English and Russian.

Later Ctrl + ↑

Common-format NSLog

It’s often inconvenient to use the full-blown debugger: longer cycles, blocks, whatever. When there’s no concern for performance, I just throw in an NSLog.

NSLog, though, is a chore when there is anything but strings involved. I do remember the format syntax but boy is it annoying to put all those %ld, %lu, %g and everything else (which would also complain on architecture change) instead of a simple %@!

So recently I started using an NSNumber literal notation for any ints and floats:

NSLog(@"%@", @(var));

Nothing to remember, no warnings, and gets the job done.

 No comments   2015   iOS

NSString+Ordinal

I put up this little category on GitHub. Feel free to use it — if you find any use for it. Below is a copy of the README file.

NSString+Ordinal

NSString+Ordinal is an NSString category for spelling numbers as words. Specifically, it’s intended for Russian ordinal numbers, for which, as far as I know, there is no direct iOS support. The category is tailored to work with numbers 0–200 in Russian and provides sensible defaults for any other number and locale.

What it does is it spells 1, 2, 3 as первый, второй, третий (first, second, third) in Russian and one, two, three in English, which is by design to be used in a phrase like «день первый» (the first day) in Russian and “day one” in English.

The category is a single method which accepts an integer:

+ (NSString *)ordinalRepresentationWithNumber:(NSInteger)ordinal;

This is probably reinventing the wheel, but I strongly believe in bootstrapped, self-written, simple solutions first. It works well for me because I know exactly how it works.

 No comments   2014   iOS

Non-breaking space in NSString

A recent project I worked on had a focus on typography, so kerning, line spacing and spacing were all important. One of the necessary steps to achieve this was to use non-breaking spaces in strings.

Turns out, it’s pretty easy, just use the Unicode representation \u00a0, which looks like this in Objective-C code:

@"This is a non-breaking\u00a0space"

Kerning, line spacing, hyphenation and other typographic features are also really interesting to implement, but they demand a longer post and illustrations, so I’ll write about them later.

 No comments   2014   iOS
Earlier Ctrl + ↓