Which direction is `UIImageOrientationUp`

UIImage has a good property named imageOrientation, all the images taken by iPhone/iPad is stored in physical orientation, when draw it on the view, most of the UIKit API and CoreGraphic API can recognize the orientation and render it it correct orientation. But if you need to resize the image or do some effect on the image by yourself, you need to calculate the image orientation by yourself. Thus you MUST understand which direction is UIImageOrientationUp.

The possible orientations

The UIImage header file defined the orientations as:

typedef enum {
    UIImageOrientationUp,            // default orientation
    UIImageOrientationDown,          // 180 deg rotation
    UIImageOrientationLeft,          // 90 deg CCW
    UIImageOrientationRight,         // 90 deg CW
    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip
    UIImageOrientationDownMirrored,  // horizontal flip
    UIImageOrientationLeftMirrored,  // vertical flip
    UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;

Fine, it is commented, but, hmm, no so well. Could you tell me which direction is the UIImageOrientationUp?

The UP orientation

It’s not the orientation when you hold your iPhone in the normal mode. Make a guess!

OK, I know your guys are not so patient, so,

Here is the correct answer: this orientation is the UP!

The UP orientation when you take a photo on iPhone

Use `DEPRECATED_ATTRIBUTE` to clean up your code

What is DEPRECATED_ATTRIBUTE

Actually, DEPRECATED_ATTRIBUTE is a macro, it is defined as:

/*
 * only certain compilers support __attribute__((deprecated))
 */
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
    #define DEPRECATED_ATTRIBUTE __attribute__((deprecated))
#else
    #define DEPRECATED_ATTRIBUTE
#endif

It’s very clear that this macro is actually using __attribute__((deprecated)) which is “One of the best (but little known) features of GNU C, which allows a developer to attach characteristics to function declarations to allow the compiler to perform more error checking”. To use it with GNU C, you need to set -Wall option to compiler. /via Steve Friedl

When and where to use DEPRECATED_ATTRIBUTE

OK, this macro is so useful, when and where should I use it?

First of all, this can be used on Objective-C method and properties.

Second, let’s see some common scenes.

  1. To deprecate a method in a widely used library. If you are writing an open-source library and you don’t want to crash your user’s app, this macro is definitely your best friend.
  2. To replace a method with new a new one. Xcode’s refactoring is not so good on adding/deleting a parameter to a method. This macro can help you a lot.

Add this macro, compile it , find the warnings, fix them, ship your app! That’s it, as simple as you can image.


You can always find me on Twitter as @TonnyXu or Facebook

How to integrate MVC pattern with GCD/KVO/CoreData in iOS

My publication

Last year, I published this article on Software Design Issue November. The whole article was written in Japanese. Since I’m not a native Japanese, I’d like to thank my fellow coworkers Nagano/7gano and Kato/guruguruman to help me review the article again and again. Without your help, I could not make this happen.

View the content

The Japanese title of this article is iOS でのMVCパターンの再検討およびCore Data、GCD、KVOの実践運用

The article was coordinated with Gihyo‘s format and it’s hard to layout it again, so, I’d like to share the finished page in PDF with everyone.

View the article in PDF

Brief content in English

  • CoreData is powerful, and if you don’t have legacy database to conform to, use it
  • KVO is super powerful, but come with side effect. It can help you with your multiple UI update, and can also mess your code flow
  • GCD is awesome! forget about delegate, use GCD whenever possible with multithread programming
  • All these technologies comes great with MVC pattern

Finally, as always, follow me on Twitter or Facebook

Jan 19, 2011, public speech at PasonaTech Japan

User, User, User

This is a public speech I gave to PasonaTech‘s seminar on smart phone development. Basically, this is not a technical speech, in this session, I proposed that every engineer should focus on what the user really want, not just what your superior what. In order to do so, you need to whatever you can on the full development process.


As always, remember to follow me on Twitter, or on Facebook