Friday, June 1, 2012

Don’t miss these cool stuff in D10

Tim Cook talked about Apple

See the video here: Tim Cook on Steve Jobs , Apple TV and Facebook: The D10 highlights

Mary Meeker release Internet trends of 2012

See this 98 pages report:

KPCB Internet Trends – 2012

Via Tonny Xu Social, Something really cool!

Wednesday, May 23, 2012

An excellent handbook: “Facebook for business” from released an excellent facebook handbook for business. This is such a good handbook, I’d like to share this in my blog.

The handbook was written in Japanese. Hope you can read it.

Although it was written in September 2011, but it still has huge value for anyone who want to apply Facebook to their business.

Meanwhile, my colleague Yazawa Osamu and his company Socialand is also pioneer on helping business user to expand their business on Facebook.

handbook on Slidershare

Via Tonny Xu Social, Something really cool!

Tuesday, May 22, 2012

WWDC2012 eve @Tokyo

WWDC 2012 will be open within 3 weeks, I’d like to have a WWDC2012 eve party at my company Voyage Group. iOS developers who can go WWDC from Tokyo, if you have time on Friday, June 1st evening, please come!

How to register

Please visit: ATND and register yourself.



includes: * Free beer/Free softdrink * Free Pizza/Sushi

Date and time

June 1st, 2012 7pm~10pm


AJITO of Voyage Group 〒150-0045 8F 8-16 Shinsen-cho Shibuya-ku, Tokyo


  • Making new friends
  • Exchanging hotel/tour/visit information, etc.

OK, let’s meet up on June 1st, at 7:00pm

Via Tonny Xu iPhone Dev, Something really cool!

Saturday, May 12, 2012

An object in Cocoa, but do not use `*`?


via NedraI via CC License

A funny question

Here is the funny question:

Is there any object in Cocoa/Objective-C that is a object but you do not use * to indicate it?

Now, think a few seconds before you read on: is there any such kind of objects?

NO? are you sure about that?

The Answer

The answer is YES! Yeah, there is a such kind of object in Cocoa/Objective-C.

It is the Block object!


Apple brought Block, a much more common name is Closure. As you can see from the wiki page, it is a non-standard extention to C/C++/Objective-C 2.0

Because it is an extension not only to Objective-C, but also to C/C++, so it has some special treatment.

Because Block has ^

To indicate a piece of code as a Block(or a Closure), it DOES need something like a pointer, but not a normal pointer. It act as a function pointer, but much more powerful.

So Apple introduced ^ as a replacement of * to Block.

In Objective-C ^ == *

As we can see, ^ is also a pointer, so why do we need another * to pointer to a Block?

Sample code

Use it as a method argument

  typedef void (^MyBlock)(void);  - (void)doSomethingWith:(MyBlock)block;    

Use it as a property

  typedef void (^YourBlock)(void);  @property (nonatomic, copy) YourBlock block;    

Use it as a function argument

  typedef void (^HisBlock)(void);  void myfunction(HisBlock block);    

Note that, none of above is using * to indicate a block, because the typedef has already indicated it is an object.

Of course, don’t forget to follow me @TonnyXu and Facebook

Via Tonny Xu iPhone Dev

A Quick and Clean Way to Test Your HTTP GET and POST request


photo via Corey Templeton via CC License

Well, this post is simple, HTTP POST is relatively complex than HTTP GET, some times you want to do a quick test with your post data.

Here are the solutions I know. If you have any other solutions, let me know.

A Free POST Only Test Sever

Access: This will dump all the http data for you. A good/bad approach of this site I like is that this site will record your request and you can review your request later. But we are not always just want to view the data in web page, sometimes, we also want to use it in unit test.

For example I had posted a request and your can see it here:

It’s a test from an iOS App I recently work on.

The Ultimate Solution for Testing HTTP Request

This is the BEST site I know for test HTTP request. As it listed on the home page, there many test endpoint:


/ This page.
/ip Returns Origin IP.
/user-agent Returns user-agent.
/headers Returns header dict.
/get Returns GET data.
/post Returns POST data.
/put Returns PUT data.
/delete Returns DELETE data.
/gzip Returns gzip-encoded data.
/status/:code Returns given HTTP Status code.
/response-headers?key=val Returns given response headers.
/redirect/:n 302 Redirects n times.
/relative-redirect/:n 302 Relative redirects n times.
/cookies Returns cookie data.
/cookies/set/:name/:value Sets a simple cookie.
/basic-auth/:user/:passwd Challenges HTTPBasic Auth.
/hidden-basic-auth/:user/:passwd 404′d BasicAuth.
/digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth.
/stream/:n Streams n–100 lines.
/delay/:n Delays responding for n–10 seconds.

This site is really awesome! Just try it!

Any suggestion?

If you have any suggestion or better solutions, please leave a comment.

Of course, don’t forget to follow me @TonnyXu and Facebook

Via Tonny Xu iPhone Dev

Wednesday, April 4, 2012

Think different


Good things are always inspirational, this ad not only inspired a lot of Appler, but also encouraged me to do what I want to do.

Many thanks to Steve Jobs. I will always miss you.

The scripts

Here’s to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently.

They’re not fond of rules. And they have no respect for the status quo.

You can quote them, disagree with them, glorify or vilify them. About the only thing you can’t do is ignore them. Because they change things. They push the human race forward.

While some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.

The video

Think different(HD)

The icon of

Via Tonny Xu Something really cool!

Monday, April 2, 2012

Make the UITableView with group style to round the image.

The point is, the roundCorner is draw by a subview of UITableViewCell, and mean while, it’s not a public class, there is no way you can get layer.cornerRadius from any view. So we need to resolve this problem by ourselves.

There are 2 cases.

  1. There is only one cell.

    This case is ease, just use cell.contentView.layer.cornerRadius and cell.contentView.layer.masksToBounds to make it work.

  2. There are more than one cell.

    This case is a little bit difficult. We need to deal each cell separately. Use the cell.contentView.layer.mask property to make it work. The first cell and the last cell has different round corner position. So draw the path and make it work.

Via Tonny Xu iPhone Dev, Programming, Tips

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

Via Tonny Xu iPhone Dev, Tips

Use `DEPRECATED_ATTRIBUTE` to clean up your code


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 

Tuesday, March 27, 2012

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

Via Tonny Xu iPhone Dev

Monday, March 26, 2012

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

Via Tonny Xu General, iPhone Dev, Programming

Sunday, March 25, 2012

Fibonacci Number

Fibonacci Number is a very common topic in everyday life, because it has a tight relationship with golden ratio Φ(Phi).

In CS, calculate the nth fibonacci number is also an interesting problem. Here is a Lightening Talk I gave to my company’s engineer on March 22, 2012. Take a look at it if you are looking for a job now, or you just don’t know how to calculate a fibonacci number.

Meanwhile, don’t forget to follow me on twitter, or on Facebook

Via Tonny Xu iPhone Dev, Programming, Tips

Saturday, March 24, 2012

mixi API SDK for iOS sucks

この記事は仕事で使ったmixi API SDK for iOSの感想を記録したものです。完全に個人の意見です、勤務先の会社と全く関係ありません。

このエントリーを書いた時点の最新版はV1.3.2(March 1st, 2012)です。その後、V1.3.3 (March 15th, 2012)がリリースされました。


1.3.3なのに、Sample プロジェクトがない?




V1.3.2の時、OAuthのtokenを取得したら、store/restoreができないというバグがありました。それはありえないでしょう! 一応僕がこのバグをmixiの開発者に報告して確認してもらって、3/15にリリースされた1.3.3で直されました。


iOS 4のリリースからまもなく2年, iOS 5のリリースから半年, まだBlockを使っていない?

iOS 4.0は2010年6月21日に正式にリリースされて、iOS 5.0は2011年10月12日に正式にリリースされました。

つまりmixi API SDK for iOSを開発し始めた時点は既にBlockとGCDを使えました。何故か使っていないのか分かりまへん!


何故かセットにするのが必要ですか?簡単な例です:mixi Photoのアルバムを取得するために、必ず2回のAPIリクエストを叩かないと行けないです。なぜなら、簡単公開のアルバムのリクエストとその他アルバムのリクエストが違います。

そもそも、Blockを使えばこれは一発で解決できます。現在僕らが苦労をしないとdelegateのメソッドが呼ばれる時、どのリクエストからのリスポンスのかさっぱりわかりません。 mixi公式アプリでは全部一つのページで一つのAPIをしか叩かないですか?


なぜかというと、JSONの解析が失敗した!何だと!!!?レスポンスはHTTP 200のみです。テストする時、削除などのテストをしないの????馬鹿野郎!



  1. client_id = consumer_key, googleの検索結果も全部Consumer keyの意味です。しかも、同じ技術仕様の中に、AndroidもConsumer keyの意味です。
  2. client_id = mixi-phone-ios_xxxxxx,しかし、このページではxxxxxxの意味は一切説明していなかった。




Source Codeを公開しているのに、githubなどを使っていないの?



URL schemeから起動した時の挙動がおかしい、通常のアプリロジックと混ざっています。URL schemeからの起動であれば、明らかに認証の事を優先すべきじゃないですか?


adプログラムのviewのaddOnTopaddOn:メソッドは全然tab viewとnavigation viewを対応していない。


なお、fade in/fade outなどのanimationを全く考えていないでしょう。ちょっとだけその考えがあったら、アイコンの背景色を除くべきでしょう??

mixi API SDK for iOSを使うと、ストレス対策を事前に用意したほうがオススメ





Via Tonny Xu General, iPhone Dev

Saturday, March 17, 2012

The next generation: Objective-C 2.2 or Objective-C 3.0?

According to a recent post by Big Nerd Ranch Weblog, the most recent Clang build now support Objective-C Literal feature.


This is gonna be the most exciting part of this year’s WWDC! I believe Apple will announce this feature in this year’s WWDC. Damn it, I can’t miss that!

What’s Objetive-C Literal syntax feature?

According Ted Kremenek from apple who committed a large patch to llvm repository recently(On March 6th, 2012)

Add clang support for new Objective-C literal syntax for NSDictionary, NSArray, NSNumber, and boolean literals. This includes both Sema and Codegen support. Included is also support for new Objective-C container subscripting.

My apologies for the large patch. It was very difficult to break apart. The patch introduces changes to the driver as well to cause clang to link in additional runtime support when needed to support the new language features.

Docs are forthcoming to document the implementation and behavior of these features.

Is it just like the boxing/unboxing feature in Java?

Yes, it is.

This feature makes Objective-C much more easy to use and much more like a modern high-level programming language while maintain the downward compatibility with C.

NOTE: Java introduced auto boxing/unboxing in 2004 with Java 1.5.0.

How to use Objective-C Literal feature?

Here are some examples:

Before we start to use Objective-C Literal

 NSArray *myArray = [NSArray arrayWithObjects:                     @"string",                      [NSNumber numberWithInt:1234],                     [NSNumber numberWithFloat:12.34],                     [NSNumber numberWithLongLong:123456789012345],                     nil];  NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:                         @"Value1", @"key1",                          [NSNumber numberWithInt:1234], @"key2",                          [NSNumber numberWithBool:YES], @"key3",                          nil];  

After using Objective-C Literal

 NSArray *myArray = @[@"string", @1234, @12.34, @123456789012345, nil]; NSDictionary *myDict = @{     @"key1":@"Value1",     @"key2":@1234,     @"key3":@YES };  

Super easy, super fast! right?

What’s the next version number?

Last time Apple updated Objective-C language with block syntax, and a fantastic library for concurrent computing. There is an official version for block, that’s Objective-C V2.1.

This time, it brings some nice features which are common in Java and other dynamic language lick ruby, php, python. What’s the version we should call it?

I predicate that Apple will proudly call it V3.0. Yes, Objective-C V3.0. Let’s wait and see!

Want to have a try?

Goto clang’s page, checkout the most recent source code, build it and try to run a test case!

NOTE: if you downloaded the source in a folder with a space in the name, you might not be able to build the llvm and clang.

So, DO NOT put the source code in a folder with space

Finally, you can reach me at twitter: @tonnyxu or facebook Tonny Xu

Via Tonny Xu iPhone Dev, iPhone Romur, Programming, Something really cool!

Friday, March 16, 2012

WordPress app now support using Camera+ to take a photo


So many wonderful effects now can be used with WordPress.

Via Tonny Xu iPhone Dev

Wednesday, February 29, 2012

Tips – Using janus to manage your Vim settings.

What is janus?

From janus‘s official Github page:

This is a distribution of plug-ins and mappings for Vim, Gvim and MacVim.

Just as it statement says, it packaged some popular plug-ins and mapping for you, so you can to use a full featured Vim after you installed Vim(If you are using Mac and Lion+, that means you just need to run a command and start to use a luxury Vim).

If you are in a rush, just copy the line below and paste to your terminal.

 $ curl -Lo- | bash  

Why bothering janus?

There are many famous plug-ins for Vim. But searching and installing plugins could be a painful work.

Usually, you google it, then go to to download it, then you config it and use it. This process is fine for one plugin, what if you want to install the top 10 vim plugins for coder, what if you want to install another 10 popular plugins?

For me, I can’t go through this process again and again. Don’t even think about the weird errors popped out when you installing your plugins.

What’s the merit I can get?

With janus, all you need to know is run a command and then use it. Oh, maybe you still need to remember some command for the plugins.

Where to start?

If you have enough patient to read to here, I suggest you to take a look at janus’s Github page.

What? you just want to use it? OK, open your terminal and paste the code below.

 $ curl -Lo- | bash  

Good luck!

And, don’t forget to follow my twitter @TonnyXu

Via Tonny Xu Programming, Something really cool!, Tips

Wednesday, February 22, 2012

LLVM Compiler Overview(By Apple)

LLVM is the next generation of compiler created by Apple, intended to replace the whole GCC-family tools. It’s really, really awesome!

Here is an overview guide provided by Apple, but it hasn’t been updated for over 1 year. And during 2011, Apple released LLVM 3.1

NOTE: This page is the official release page, and will always show the most recent release. So if you visit this page and see LLVM 4.x, don’t be surprised.

Any way, it’s a good source for understanding the low level tool chains used by Apple and how apple is changing the C family compiler.

The documentations

Go to DevCenter, this page is free, no login is necessary. And all the videos has transcripts!

Other videos

Actually, the Clang community has some regular events held in San Francisco or San Jose. You can check it out from LLVM’s official site, for example, LLVM Developers’ Meeting@Nov 2011

And, as always, don’t forget to follow me @TonnyXu

Via Tonny Xu iPhone Dev, Programming

Tuesday, February 21, 2012

ARC Learning Notes(1)

ARC(Automatic Reference Counting) was introduced by Apple on WWDC 2011, along with iCloud and OS X Lion. It’s a wonderful feature we need, but, how much it has been adopted to real projects?

How many projects adopted ARC?

Currently, 0 project is using ARC in my company.

This does not mean we hadn’t started new project since ARC was released, but because we have some constraints. We are using some common libraries across our projects, and we need to maintain the libraries consistent. We also need to add many features to the apps we released, and also, using ARC means all of our team members need to learn how to use ARC and know the common practices and have a better understanding of memory usage. That’s the time we could not afford in the past 8 months.

But we know we will move to ARC inevitably. So the problem is when?

Status of My projects

Currently we started to use ARC in some test projects. Here the Test Project means we use such kind of project to test some features quickly and without infecting the real projects.

What about yours?

How about yours? Are you starting to use ARC in your project now? Tell me about your projects’ status in the comment please.

It’s the time!

After 8 months, by watching a lot of Open Source project adopting ARC, I think it is our time to start using ARC from now on.

ARC only needs the new compiler, and it has a good backward compatibility to iOS 4. So let’s just try it.

Start from where?

Where should we start from? I think we can start from 2 things.

Apple’s document

Apple’s DevCenter for iOS has a good document for using ARC. Here is a simple list as far as I know.

  1. What’s New in iOS 5
  2. Transitioning to ARC Release Notes
  3. Advanced Memory Management Programming Guide
  4. Memory Management Programming Guide for Core Foundation

WWDC 2011′s HD Video

Also, WWDC 2011′s videos are great, don’t miss this one.

  1. Session 323 – Introducing Automatic Reference Counting

Next time, I will post what I learned about ARC.

And as always, don’t forget to follow me @TonnyXu

Via Tonny Xu iPhone Dev, Programming

Saturday, February 11, 2012

Using purge command in Mac

Have you ever heard about the command purge? Hmmm, never heard about it? Well, that’s means you are view the right page.

Let me change the question.

Have you ever met a situation like this?

8GB, but full figure 1

Holy shit, 8GB DDR3 memory is still not enough?


Most of the time, I will blame my default browser: chrome! Usually, when I quit chrome, it will free 3GB+ memory, and my Lion system will go smoothly again.

But, chrome is not always the reason of high consumption of my physical memory. I don’t know which one is using a huge bunch of memory then leave it as INACTIVE, just as figure 1 looks like. The blue pie is huge! and the most important thing is it is INACTIVE.

What’s next?

OK, here purge comes to rescue, open your terminal, then type:

 %: purge  

BOOOOM! my system looks like as below, and feels much more faster!

after using purge

What happened?

The story behind the scene is relatively complicated, you can read Apple’s document. But anyway, it’s a shortcut to free your valuable INACTIVE memory.

Don’t forget to follow me @TonnyXu

Via Tonny Xu Something really cool!, Tips

Friday, February 10, 2012

Using sed command in Mac OS X

It’s easy to use sed command, right?

 %: sed -i "s/old/replace/g" mysql.txt  

This tip is all around the net. But! it doesn’t work with Mac!

WTF? How to make it work?

Try it yourself, I’m using Lion 10.7.3, it cost me over 30 minutes to search and read the man page.

-i extension

Edit files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved. It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situations where disk space is exhausted, etc.

What is a zero-length extension? Try this:

 %: sed -i "" "s/old/replace/g" mysql.txt  

The empty string behind -i as -i "" is the KEY point.

Replace in multiple files

Try this:

 %: find path/to/search -name "*.php" -exec sed -i "" "s/old/replace/g" {} \;  

Good luck! Don’t forget to follow me @TonnyXu

Via Tonny Xu Tips

Have you seen MIN and MAX macro in Objective-C

How will you write a MIN(a, b) or MAX(a, b) macro?

In the real world, it is easy to tell which is the minimum and which is the maximum of 2 numbers. But to write a correct function in computer, it’s not an easy job as we can see.

Usually, MIN and MAX functions are written in macro, so how will you write it?

 #define MYMIN1(a, b) {a < b ? a : b;}  

This is definitely wrong, at least you need to add the parenthesis to the parameters. OK, it’s easy, let’s add this:

 #define MYMIN2(a, b) ({(a) < (b) ? (a) : (b);})  

But, this is still wrong. Let’s take a look at what Objective-C and other languages defines these 2 macros.

How does Objective-C define MIN and MAX?

Because there is no MIN or MAX defined by C standard library, Objective-C defined this in NSObjCRuntime.h

Let’s see the code:

 #if !defined(MIN) #define MIN(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) 

Thursday, February 2, 2012

CoreData with NSOrderedSet does not work well on insertion

Usually, we generate an entity class with Editor->Create NSManagedOBject Subclass... For example we created a subclass of NSManagedObject

Xcode generates the .h file like this:

 @interface MyEntity : NSManagedObject  @property (nonatomic, retain) NSOrderedSet manySubs;  //... some methods generated by Xcode - (void)addManySubsObject:(MySubEntity*)value; //... some other methods generated by Xcode  @end  

and the .m file like this:

 @implement MyEntity  @dynamic manySubs;  @end  

If you use MyEntity just like this, you will get an error when you try to insert a new MySubEntity class by calling [myEntityObj addManySubsObject:aSubEntityObj];.

The error reads:

*** -[NSSet intersectsSet:]: set argument is not an NSSet

This is a bug Apple hasn’t resolved yet, but you can work around this bug by adding the following method to .m file.

 - (void)addManySubsObject:(MySubEntity*)value{     [self willChangeValueForKey:@"manySubs"];     NSMutableOrderedSet *tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.manySubs];     [tempSet addObject: value];     self.manySubs = tempSet;     [self didChangeValueForKey:@"manySubs"]; }  

Be careful

Via Tonny Xu iPhone Dev, Programming

Tuesday, January 24, 2012

Sunday, January 22, 2012

Transparent view vs. hidden view in iOS

Rise the question

Here comes the question,

how to create a transparent view without any contents?

Wow, the answer looks so easy to get! Almost every iOS developer has created one or even more ‘transparent view’s. Let’s take a look at those solutions. We have 2 solutions.

Solutions #1

Create a view with alpha=0.f. take a look at the code below

 UIView *transparentView1 = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 460.f)]; transparentView1.alpha = 0.f; [self.view addSubview:transparentView1]; [transparentView1 release];  

It’s simple and straight forward. Hum? Let’s take a look at another solution.

Solution #2

Create a view with backgroundColor=[UIColor clearColor].

 UIView *transparentView2 = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 460.f)]; transparentView2.backgroundColor = [UIColor clearColor]; [self.view addSubview:transparentView2]; [transparentView2 release];  

This is also very simple.

So, what’s the difference between these 2 solutions?

The difference on surface

Before we talking about the difference, we need to review some basic yet key properties provided by iOS

  1. hidden: set this property to YES will cause the view invisible. default is NO;
  2. alpha: this property affect all the contents of the view, including drawing and subviews. animatable;
  3. backgroundColor: this only affect the background color, not affect the drawing and subviews of the view. animatable;
  4. opaque: set this property to YES, will gain some performance boost on UI rendering. But need to full fill the rectangle of the view. If opaque is set to YES and the view has full or partial transparent content, the behavior is not define.

Visit apple’s document for UIView for detail information.

With these basic knowledge, we can easily tell the difference between these 2 solutions.

  • Solution #1 uses alpha property to make the view transparent, in another word, it’s invisible because the view is hidden.
  • Solution #2 sets backgroundColor to transparent color to make it invisible.
  • Solution #2 only set the background to transparent, if you draw anything on the view, or add some subviews to the view, they are still visible, and solution #1 will make everything in the view invisible, including the custom drawings and all the subviews.
  • If the view is a clean view without any custom drawings and subviews, the result of these 2 solutions look the same.

They look the same? But actually not the same? Yes, they just look the same, but not exactly the same, so what’s the real difference?

Look the same, but…

There is always a BUT.

These 2 solutions look the same, but act differently on receiving touch event.

  • Solution #1: alpha=0.f;, according to Apple’s document:
    > To hide a view visually, you can either set its hidden property to YES or change its alpha property to 0.0. A hidden view does not receive touch events from the system. However, hidden views do participate in autoresizing and other layout operations associated with the view hierarchy. Thus, hiding a view is often a convenient alternative to removing views from your view hierarchy, especially if you plan to show the views again at some point soon.
    > See Apple’s document
  • Solution #2: when background color is set to clear color, the alpha is still 1.0, so this view still can receive touch event.

Finally, we have the answer

Before we get the correct answer, we need to use the correct terminologies to clarify the answer:

  • Hidden View: when hidden=YES or alpha=0.f
  • Transparent background View: when backgroundColor is set to clear color

The answer

  • a hidden view will not accept touch event, while a transparent background view will.
  • a hidden view may look like a transparent background view if add no subviews and draw nothing on the view.

With this answer, I think we can use hidden view and transparent background view correctly.

Via Tonny Xu iPhone Dev

Friday, January 13, 2012

How to sync WordPress blog entries to and Tumblr and Posterous

Do you have multiple blog sites?

If your answer is no, then, this blog entry is useless to you. Close this page please.

If you DO have multiple blog sites, and you don’t care about synchronizing one blog site to others, then this blog entry is also useless to you. Close this page please.

If you DO have multiple blog sites as me, and you DO want to synchronize your one blog site to others. You are viewing the right post.

Why multiple blog site?

It’s complicated. I’m owning my own domain, and is running WordPress on it. Then I also have an account in, it’s good, with elegant design and dashboard. I also happened to have an account in all because it support markdown by default.

So, I like all of these 3 sites, and I don’t want to abandon any one of them. I decided to do a synchronization with all of these sites.

But, How?

Have you ever heard about ““?

This site is great! It saved me a lot of works. Synchronizing between each site is also done with‘s help.

Here is how:

  1. You need to have a main site. This means, you need to post your original posts to this site. Since all blog systems provide RSS output, we will use RSS to synchronize entries to other sites.

  2. Add a new rule in You usually, it can be read as “Sync any new items in RSS[your main site's RSS] to tumblr/posterous/Mail(etc.)”. It’s very straight forward, and easy to use. Just create a few such kind of rules to let it do the synchronizing works.

  3. is not directly supported by

My solution is enable the “Posting using email” option in, then setup a rule to send an email to your posting email address on each new blog entry. can do much more things

[] is such an awesome site, it integrated almost all the major web services in the world. You can send a tweet or a facebook post when your new blog entry is posted.

The concept can be separated as read in stream and output stream:

  • read in stream: services available for read in stream

  • output stream: services available for output stream

Now, just enjoy the internet!

Via Tonny Xu Blog System, My Blog, Test Post