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.

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

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

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.

WOW!

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