2008年2月29日 星期五

NSString and NSMutableString

use @"abc" to mean NSString
ex: NSString *str = @"Hello";

use content of file to create NSString
ex: NSString *str = [NSString stringWithContentsOfFile:@"/path/to/file"]

use c characters to create NSString
ex: char *cStr="hello";
NSString *str = [NSString stringWithCString: cStr]

get length of NSString
ex: unsigned int strLen = [str length]

append on NSString to another
ex: NSString *str = @"Hello";
NSString *str2 = [str stringByAppendingString: @"abc"]

append a format:
ex: NSString *str3 = [str2 stringByAppendingFormat: @"%d", 2003]

search for subString:
ex: NSRange loc = [str rangeOfString:@"The"]

what is NSRange:
typedef struct _NSRange{
unsigned int location;
unsigned int length;
}NSRange;

breaking a string into components:
ex: NSArray *fields = [str componentsSeperatedByString:@"abc"];

create NSMutableString from NSString:
ex: NSString *str = @"hello";
NSMutableString *ms = [NSMutableString stringWithString: str];

mutable and immutable

immutable class means you can not alter after initialization
ex: NSString, NSArray

mutable class means you can alter after initialization, it extends from immutable class
ex: NSMutableString, MSMutableArray

2008年2月28日 星期四

ButtonGroup

同一個group裡的button,只有一個會被選。

how to use:
1. create ButtonGroup object
2. add buttons to ButtonGroup object

目前時間 in java

利用Calendar class
java.util.Calendar

ex: 顯示目前幾點
Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
顯示目前幾分
Calendar.getInstance().get(Calendar.MINUTE)

icon composer

create software's icon

/Developer/Applications/Utilities

how to set application's icon:
modify info.plist
ex:
CFBundleIconFile
APPL

xcode 指令

在function名稱上,option+double click:
show document to explain the function

在function名稱上,apple + double click:
show the function's header file

2008年2月27日 星期三

mvc

mvc( model, view, controller)

model: 實際做的function,例如1加到100
view: user看到的GUI

controller: 讓view和model能溝通,使得model運算的結果可以更新到view上,例如更新在text field上。

declared property

目的: 節省自己寫getter, setter來access instance variable的時間。


how to define:
@property(attributes) Type variableNameList;
ex: @prperty(copy) NSString *name;

where is the location to define?
in header file, after close brace ( } )

how to define method:
use synthesize, the compiler will define accessor methods for you:
ex: @synthesize dog;

interface builder and nib

use interface builder to create GUI

nib:(NeXT interface builder): created by interface builder

double-click on nib file will open interface builder. Then you can modify GUI

outlet: an instance variable that points to other object
when a object A want to send messages to another object B, it must defined B as its outlet
outlet is defined as IBOutlet:
ex: IBOutlet NSTextField textfield;

action: 要做的事情
action is defined as IBAction
ex: (IBAction) action: (id) sender


設定outlet and action:
ctrl+ mouse
If A want to send messages to B, connect from A to B

how to create a object in interface builder:
define class' header
In Interface builder, choose File-> read class files , choose class' header file
move object from library to mainMenu.nib
change object's class to your class name( under class identify)

memory management in objective-c

before objective-c 2.0, there is no garbage collection
Hence, it is necessary to manage memory

every variable has a retain count. when its retain count becomes 0, it is released.

retain count在什麼時候會+1
(1)use "retain" on object: ex [dog retain]
(2) object created by "alloc", "copy", "new", "mutableCopy"
(3) when object is add to array

retain count在什麼時候會-1
(1)use "release" on object
(2)when object is removed from array

autorelease pool:
objects are added to autorelease pool when they are sent message "autorelease".
when the autorelease pool is deallocated, it sends message "release" to objects in the poll

2008年2月26日 星期二

netstat

show network status

-r:
Show the routing tables

-a:
顯示在本地機器上的外部連接

-p:
Show the PID and name of the program to which each socket belongs.

vmware fusion

shared location
/mnt/hgfs

wget

get file from http or ftp
ex: wget http://www.open-iscsi.org/bits/open-iscsi-2.0-865.15.tar.gz

2008年2月25日 星期一

yast

suse上的software management

NSObject

method:
isMemberOfClass:
判斷object是否是某個class

isKindOfClass:
判斷object是否是某個class 或是inherit from that class

2008年2月24日 星期日

garbage collection in objective-c

default, gc is not enabled.

how to enable it:
in Xcode, in the target, in the build panel,
under gcc-4.0,
in Objective-c garbage collection, choose supported( -fobjc-gc)
This means your application can uses gc & retain/release method
If choose required( -fobjc-gc-only) , your application can only use gc
required mode is more recommended.

objective-c syntax

use import to include header file

define class:
@interface Dog: NSObject {
int head;
}
-(void) print: (int) d;
@end;

(1) Dog extends NSObject, @interface = Java's class
(2) instance variables are defined between { }
(3) default access is protected
(4) method's syntax: - (return type) name: (parameter1 type) parameter;
- means instance method, static method(class method) uses +

how to access public instance variable
ex: ceo object has instance variable boss,
ceo -> boss

how to define method with multiple parameters:
ex: -(void) eat: (int) n andDrink: (int) d;
andDrink is label name. It is optional, but is recommended

how to call method:
[object method], ex: [dog eat] = dog->method in Java
objective-c does not have value type. It is always pointer type. Hence, [dog eat] = dog->method, not dog.method

how to call method with parameters
ex: (1)[dog eat: 1 :2]
1 and 2 are the parameters
(2) [dog eat: 1 drink:2]
1 and 2 are the parameters
alloc and init method:
alloc: allocate memory, ex: [Dog alloc]
init: initialize variable in the object
Use alloc and init to create new object: ex: Dog *dog = [[Dog alloc] init];

how to define constructor :
call "self = [super init];" in the constructor definition
self is like "this" in Java, super means parent, call parent's init method to init object

nil:
nil = NULL in C

access privileges:
ex:
@public
int a;
@private
int b;
@protected
int c

id:
a type, a general pointer to an object, the type of object is determined at runtime

self and super:
self = this in Java
super = super in Java

2008年2月23日 星期六

台北賣的chocolate

微風 Michel Cluizel
A11館B1 Cacao et Chocolat

2008年2月20日 星期三

線上TV

http://www.free-tv-video-online.info/

http://www.videolemon.com/

http://www14.alluc.org/alluc/

USA proxy
192.104.67.250 8080

2008年2月19日 星期二

JBuilder 指令

F3:
在function上按F3,進入定義此function之處。

桌球地點

長城桌球板橋店
板橋市民權路79號

板橋 奧林匹克球場
莊敬路136號地下室

probe() in mac driver

driver判斷要match到哪一個device:
driver和device溝通,決定device是否適合。

static and extern

default( global variable/function前不加東西)
his variable/ function在此定義,且可以別的檔案存取。

在global variable/function前加上static:
his variable/ function只能在這個檔案使用

在global variable/function前加上extern:
this variable/ function在別的檔案定義

little endian and big endian

little endian:
the least significant byte comes first
ex:
0x1122 is store as 22 11

2008年2月18日 星期一

compile with framework

compile files that connect to user client in the kernel:
IOKit, CoreFoundation, ApplicationServices

2008年2月17日 星期日

JNI

檔名:
.jnilib : mac os x , prefixed by lib and suffixed with .jnilib
.so : solaris and linux
.dll: windows

in library file:
(1) include
(2) function格式:
ex: JNIEXPORT jint JNICALL Java_Test_show(JNIEnv *env, jobject rkObject)
function name = Java_Test_show, 以Java開頭,接著是溝通的Java的class name,最後才是function name
如果Java是在某個package上,要包含package name, 例如class Dog在package Animal下,
則完整的function name是Java_Animal_Dog_eat()
JNIEXPORT and JNICALL make this function to be found
(3)compile:
gcc -c -I /System/Library/Frameworks/JavaVM.framework/Headers test.c

如果是在xcode,在target info panel下的 build tab下的Header Search Paths設成/System/Library/Frameworks/JavaVM.framework/Headers
(4) product jnilib file
gcc -dynamiclib -o libtest.jnilib test.o -framework JavaVM


in Java
(1) check path, jnilib檔的位置要在path上
System.out.println( System.getProperty( "java.library.path" ) );
(2) loads the library named libhello.jnilib
System.loadLibrary("hello")
(3) 宣告要呼叫的library function
ex: public native void show();
以public native開頭


把Array 的結果copy back to 呼叫端
(*env)->ReleaseIntArrayElements(env, ctrllist, jBody, 0);

圖書館

台北市立圖書館
臺北市建國南路二段125號
台北火車站(衡陽路)搭公車22路,
在建國南路與信義路口下
週二至週六:8時30分至21時;週日、週一:9時至17時

西門智慧圖書館

四號公園 中央圖書館

2008年2月16日 星期六

piano的dvd

The Golden Age of Piano

音樂相關的去處

中正文化中心
台北市中山南路21-1號
捷運 中正紀念堂站 五號出口

國家音樂廳( 閔的古典音樂世界)

表演藝術圖書館
週一至週五 9:00~20:00
週六、日中午12:00-20:00
典藏卡 1500

蕭邦

值得購買的演奏家:
魯賓斯坦 Arthur Rubinstein

2008年2月12日 星期二

html and xml 注解

iolog

defined in IOLib.h


Log a message to console in text mode, and /var/log/system.log.

2008年2月1日 星期五