Thursday, December 23, 2010

Great Year 2010 and Embracing the New Year 2011

Year 2010 is coming to the end. I have a great year 2010. I have been working in one company as an IT consultant for the whole year. Even though the job requirement are not very challenge, I have been always set up new heights for me and continue to learn and explore new stuff in this year. This is very productive year for me. Not only I gained so much in a wide range of areas, but I also pick some of my old skills and knowledge back, such as OPC and COM in Windows. I feel very applaud of myself when I see my accomplishments.

In addition to my work, I have spent much my after-work time on personal persuasions. I think I have made great progress in my iOS development. My application is close to the finish stage. During the development, I have gained great skills and knowledge of Objective-C, Cocoa framework, and iOS. I enjoy my journey in the year of 2010. At the same time, as always, I have been keeping up with the evolution of iOS in past two years. I watched all the technical videos of WWDC 2010, and some wonderful podcasts such as CTN, and app review shows.

The most important thing I have to say about my year in 2010 is the web or internet. In a sense, it really extend my life. Without it I would spend more time and energy to struggle. I have taken so much from the web, the open community: learning, enjoying and sharing. It has enriched my life so much. I am so grateful to live in such a wonderful time and word.

I like two phrases. One is "stay hungry and stay foolish", from Steve Jobs' 2005 Stanford Commencement Address. Another one is "You Can't Take Money to Eternity", same applies to knowledge. I want to stay as I am and to share what I have. This is the way to extend human's life.

Now it is time to embrace the New Year 2011!

Read More...

Sunday, December 19, 2010

NULL Issues in ABContact Open Source Project

I found a nice open source project for Mac/iOS Address Book data source. The project contains several key wrapper classes: ABContact, ABGroup, and ABContactsHeler. Mac OS/iOS has extensive APIs for accessing and editing AB records, but they are all C libraries. The project provides nice Objective-C wrapper classes for those libraries.

Today, I found several bugs with multi value properties. Some NULL issues in the wrapper class ABContact.m methods have not been handled. As a result, I got EXC_BAD_ACCESS exception. Basically, if a record has no multi-value property defined, for example address property, the CFTypeRef value will be NULL. The fix is very easy: checking NULL before using CFTypeRef value. Here are my updated codes:

#pragma mark -
#pragma mark Getting MultiValue Elements
- (NSArray *) arrayForProperty: (ABPropertyID) anID
{
NSArray *items = [NSArray array];
CFTypeRef theProperty = ABRecordCopyValue(record, anID);
// the return value is NULL if no multi property is defined for the record.
// therefore, check its NULL first before getting values
// Updated by David Chu, same apply to the following methods
if (theProperty != NULL ) {
items = (NSArray *)ABMultiValueCopyArrayOfAllValues(theProperty);
CFRelease(theProperty);
[items autorelease];
}
return items;
}

- (NSArray *) labelsForProperty: (ABPropertyID) anID
{
NSMutableArray *labels = [NSMutableArray array];
CFTypeRef theProperty = ABRecordCopyValue(record, anID);
if ( theProperty != NULL ) {
for (int i = 0; i < ABMultiValueGetCount(theProperty); i++)
{
NSString *label = (NSString *)ABMultiValueCopyLabelAtIndex(theProperty, i);
[labels addObject:label];
[label release];
}
CFRelease(theProperty);
}
return labels;
}

+ (NSArray *) arrayForProperty: (ABPropertyID) anID inRecord: (ABRecordRef) record
{
NSArray *items = [NSArray array];
// Recover the property for a given record
CFTypeRef theProperty = ABRecordCopyValue(record, anID);
if (theProperty != NULL) {
items = (NSArray *)ABMultiValueCopyArrayOfAllValues(theProperty);
CFRelease(theProperty);
[items autorelease];
}
return items;
}

The original codes do not check NULL cases. With those updates, my codes resume normal. In addition to NULL checking, I also make sure there is no memory leak, as the same way as the original codes do. All the copied NSArray result are set with autorelease.

Read More...

Wednesday, December 15, 2010

XCode Splash Screen

Just finished watch a short podcast show by CTN (Cocoa Touch Netcast). It is about 2 minutes show on how to enable settings for XCode Splash screen. For example, this is my XCode splash screen:


The way offered by Robert is actually to edit the plist file in /Library.... I don't like this way to modify plist file, since it may mess up the file. Instead, I prefer to use console tool or command defaults to modify it.

First, check the default setting. Open Terminal and type the command:

defaults read com.apple.xcode XCShowSplashScreen 1

or use the pipe and grep command to search for "Splash"

defaults read com.apple.xcode |grep Splash

I did not find the setting for XCShowSplashScreen. I have never disabled my splash screen. It looks like that the default setting is to show the splash screen if the setting is not defined in plist. Then I disabled my splash screen and use the defaults read command to read it again. After that, I saw it was set to 0.

To enable it, use the defaults write command:

defaults write com.apple.xcode XCShowSplashScreen 1

You may check it again by defaults read command.

Read More...

Saturday, December 04, 2010

PowerShell Tip: Dynamic Data Type

I have used PowerShell(PS) for quite a while. I really enjoy its power and great features. I did not spent time to learn PS thoroughly or systematically(such as C/C++, .Net C# or VB, or Objective-C). I just learn it by examples and by demand. The main reason is that PS covers a wide range of areas, from DOS command to .Net and other scripts. I just don't have time to learn it in a long time span.

One of PS great features is its dynamic data type. All the variables are defined by $ prefix. You can define a variable with strong data type. However, sometimes you just need to take the advantage of its dynamic data type. For example, the following code is to get files. The result may be null, one file or a collection of files:

$fs = Get-Item -Path "*.txt"

In order to find out if the result contain any file, you have to check the cases of empty, one object or a collection of objects.

$fs = Get-Item -Path "*.txt"
if ($fs -eq $null) {
Echo "empty files"
}
if ($fs.Count -eq $null) {
Echo ("one file: {0}" -f $fs)
}
else {
Echo ("collection of files. Count: {0}" -f $fs.Count)
$fs
}

Read More...

XCode 3.2.5 and iOS SDK 4.2

Xcode 3.2.5 and iOS SDK 4.2 was available on November 22, 2010. I downloaded the whole package (52GB) couple weeks ago. It took me about 2hours to get the package(not sure why my Internet or browser was so slow).


I had a little trouble to compile my app after the installation, as same I did last update (3.2.5 on September 30, 2010). I had to refresh my base frameworks. This time it was much better than the previous time. I only spent about a few minutes to make my app codes working in XCode.

Read More...