2010年11月22日星期一

Few little technique on Objective-C

To test an object's type in runtime in Obj-C:

[myObject isKindOfClass:[NSString class]]

To get the mouse position on the screen:

NSPoint mouseLoc;
mouseLoc = [NSEvent mouseLocation];


To get the mouse position wrt local window:

NSPoint  point   = [self convertPoint:[theEvent locationInWindow] fromView:nil];

2010年11月18日星期四

Strong Type NSArray?

Is there any way to make NSArray become strong typed? The answer is no. (except subclassing it)

From Stackoverflow

Some ppl say it is not necessary, provided having good practice and good testing coverage.
After that I start to think of: why should I need a complier? why should I need VS or Xcode or Eclipse?
Maybe it really takes some time for me to indulge in the embrace of Apple.

2010年11月17日星期三

Cocoa NSCollectionView

Just found a useful tutorial at André's Blog when making the map editor for the new project(we are tired at making the map xml files manually).

Even it is "for dummies", it takes me some time to follow as a newcomer to Cocoa and Mac OS. The version difference even make it worser as something has changed in Xcode.

tbc

Objective C Property

http://www.cocoacast.com/?q=node/103

2010年11月2日星期二

Create Mac ICNS file for Xcode project

devdaily.com看到PNG to ICNS的教學,

FastIcns是一個方便的application, 可輕鬆把png 轉換成icns (mac的icon格式)


在Xcode裡, 把icns file 加到project中Resources/Icons & Default中
target 上 right click > GetInfo > Properties tab > Icon File 欄中輸入file的名稱,完成!=]

FastIcns project page

Converting audio file format on Mac by "afConvert"

"afConvert" is a command which could be directly used in the Terminal (I am using Mac OS X 10.6.4).

I used to convert audio file of format .m4a to .caf, which is a file format for iPhone and is actually a wrapper for a number of data formats like .mp3, LEI, acc, etc...

To make my sound file playable by my OpenAL class in iPhone SDK, I tried to change it to LEI16
"afConvert -f caff -d LEI16@44100 inputname outputname"

In order to make the files smaller, I tried using LEI8 and acc but the sounds played are weird.
I am still working on it.

Here is a shellScript for batch conversion, name the script as converttocaf.sh and all the file in that directory will be converted to the .caf format:
for f in *; do
if  [ "$f" != "converttocaf.sh" ]  then
    /usr/bin/afconvert -f caff -d LEI16@44100 $f
    echo "$f converted"
fi
done

2010年11月1日星期一

Mac Shell Script

In our project, the screen delay whenever any sound is played.
The reason is that it used AVAudioPlayer for playing all sounds and musics.
However I found that AVAudioPlayer is more for streaming but not caching, we need to shift to OpenAL for playing sounds.

After writing a class for OpenAL, I used much time to find out why it doesn't work.
The final answer is: it works, but it is not compatible with the original audio format ".m4a".
Then I need to find a way to convert them to ".caf" format which works well with OpenAL in iPhone.

Well, the next step is to find a way to do batch convertion with afConvert.
Finally comes to the topic: using shellScript on Mac.

(the above topics: OpenAL, afConvert to caf, afConvert batch convertion, will be discussed later)

Here is a gd answer on StackOverFlow (as always).

And it is a script for deleting all files with extension .caf in a directory: "find . -type f -name "*.caf" -exec rm -f {} \;"