Oct 8, 2008

(XCode) How to compile a XCode project using command line

XCode has a very useful toll which named xcodebuild, it allows to compile a XCode project by command line, here is an example:

xcodebuild PRODUCT_NAME="AppName"

the PRODUCT_NAME argument is defined in the info.plist of your project which means the application's name, it is also the name showen in your iPhone or simulator.

The xcodebuild command is executed only in the project directory, so you should use it in the right place.

Oct 7, 2008

(Mac OS X) How to resolve the problem that menu bar items disappear after login

It's the first time i met this problem on Mac, all my menu bar items disappeared after login. I found a solution to resolve this, delete
Users/yourname/Library/Preferences/com.apple.systemuiserver.plist then log out and back in or just a simple restart your Mac.

Sep 11, 2008

(Android) How to resolve the exception of "Table has not been deactivated or closed"

I'm working on the migration my project from M5 to 0.9, i got some exceptions of SQLite which shows "Table/Cursor has not been deactivated or closed" in my database class, i found the problems come from the Cursor. After read the API documents, i understand each opened Cursor should be deactivated and closed after reading its content. Here is an example:

Cursor cursor = sqlite.query(table, null, selection, null, null, null, null);
if (cursor.getCount() > 0){
int cursorCount = cursor.getCount();
ArrayList records = new ArrayList();
cursor.moveToFirst();
for (int i=0; i record = new HashMap();
String[] columns = cursor.getColumnNames();
int columnsNb = columns.length;
for (int column=0; column

(Objective-C) How to block thread

In the multi-threading programming, sometimes we need block the other threads to wait the result of a thread. There are several solutions:

1. Using @synchronized. With this solution, we don't create a NSThread object, here is an example:

- (void) callThreadMethod {
@synchronized(self) {
//the methods you want the thread to do
}
}

2. Using NSLock. Still don't create NSThread object, here is an example:

- (void) callThreadMethod {
NSLock *myLock = [[NSLock alloc] init];
[myLock lock];
//the methods you want the thread to do
[myLock unlock];
}

For the other solutions, you could read this great tutorial of multi-threading, Multithreading Tutorial

Sep 8, 2008

(iPhone) How to use Preference

Writing a simple data to preference:

CFStringRef textColorKey = CFSTR("defaultTextColor");
CFStringRef colorBLUE = CFSTR("BLUE");
// Set up the preference.
CFPreferencesSetAppValue(textColorKey, colorBLUE,
kCFPreferencesCurrentApplication);
// Write out the preference data.
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);

Reading a simple data from preference:

CFStringRef textColorKey = CFSTR("defaultTextColor");
CFStringRef textColor;
// Read the preference.
textColor = (CFStringRef)CFPreferencesCopyAppValue(textColorKey,
kCFPreferencesCurrentApplication);
// When finished with value, you must release it
// CFRelease(textColor);

To replace the exist key's value, just overwrite the values of key.

(Objective-C) Convert between NSString and CFStringRef

From NSString to CFStringRef:
NSString *test = @"test";
CFStringRef testCF = (CFStringRef) test;


From CFStringRef to NSString:
CFStringRef testCF = "test";
NSString *test = (NSString *) testCF;

Sep 1, 2008

End of student life

I just passed the presentation of my internship in Penbase, this means my student life is over, i finished my education of university, i am going to start the professional life.