Faryar Fathi

Composer, Coder, Entrepreneur

Tip: Hacking Private Class Methods in Objective-C

There is no such thing as a private method in Objective-C. Developers, however, use class extensions to declare the methods they don’t want to expose publicly, effectively making them ‘private’.

Let’s say you are subclassing a library class and to make it work for your application, you need to reimplement one of its private methods without replacing it. In other words, you still want be able to call super, but you also want to add your own code. Something like this:

Emmanuelle

Emmanuelle started out as an improvisation, like most of my songs. Being a huge fan of Satie’s Gnossiennes, I was trying to play something inspired by them.

What made Emmanuelle special was the ease with which I managed to write it. I usually agonize over every detail of my songs, and more often than not, they end the in a pile of more than 200 unfinished songs that I have yet to decide how to develop, end, orchestrate, etc. But this time, all I had to do was to transcribe the recorded improvisation. Although, I am not 100% satisfied it and wouldn’t mind changing things around here and there, I’ve decided not to change a single note…. at least for now!

Hope you enjoy it!

Quick Tip: Objective-C Ternary Operator

Use conditional operators (aka ternary operators) to make your code more legible and clear. Conditional assignment is the most common use case for ternary operators.

With the ternary operator, you can turn this:

1
2
3
4
5
6
7
int days;

if (thisYear == leapYear) {
  days = 366;
} else {
  days = 365;
}

into this:

1
int days = (thisYear == leapYear) ? 366 : 365;

Only one line of code, and a lot easier to read and understand when you’re familiar with the syntax.

What Will Your Verse Be?

O Me! O life!… of the questions of these recurring;
Of the endless trains of the faithless—of cities fill’d with the foolish;
Of myself forever reproaching myself, (for who more foolish than I, and who more faithless?)
Of eyes that vainly crave the light—of the objects mean—of the struggle ever renew’d;
Of the poor results of all—of the plodding and sordid crowds I see around me;
Of the empty and useless years of the rest—with the rest me intertwined;

The question, O me! so sad, recurring—What good amid these, O me, O life?

Answer.

That you are here—that life exists, and identity;

That the powerful play goes on, and you will contribute a verse.

  • Walt Whitman

What will your verse be?

Objective-C Literals

When I was introduced to Objective-C, its verbose syntax seemed annoying and even unnecessary. But I quickly learned to appreciate the clarity that it often provides and eventually that very same verbosity became one of the reasons that I enjoy writing code in Objective-C. However, there are a few frequently used classes in the Foundation framework that have literal equivalents, and I have opted to use them since they can make my code more concise, easier to read and easier to debug.

Let’s have a look at them, shall we?

Be Yourself

To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.

Ralph Waldo Emerson

A Half Forgotten Dream

Dedicating my life to music has been a dream of mine for a very long time. I’ve always believed that music is my true calling and I regret not following my heart and not pursuing music professionally.

I used to console myself and say, “You can do it in the future, when you have more free time.” But life was going on at full speed, and what was once a consuming dream, was fading away with each passing day.

Hello World!

Testing 1 2 3 …

1
2
3
4
5
6
7
8
9
10
11
12
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {

        NSLog(@"Hello, World!");

    }
    return 0;
}