2008年6月27日 星期五

find command

ex:
find  .   -name  "test.c"
first argument set the path to find
second argument set the file to find

2008年6月25日 星期三

build java project from eclipse in xcode

prepare:
change Java template in Xcode
edit  /Developer/Library/Xcode/Project Templates/Java/Java Applicationex/build.xml
       source="1.5"  target="1.5"

(1)check out project "Test" from cvs
(2)create the Java project named "Test"
(3)now xcode create build.xml to compile your Java project 

include external jars
place jars in   Test/lib/

set main function:
in Info.plist,  set value = packageName.className  for key = MainClass
in Manifest,  set  Main-Class: packageName.MainClass

set image files:
place them in Test/bin

set VMOptions
in info.plist,  set  "-Xmx512m"  for key  "VMOptions"

set class path for app:
In Info.plist, set the value of  ClassPath
ex:

<key>ClassPath</key>

<array>

<string>$JAVAROOT/test1.jar</string>

<string>$JAVAROOT/test2.jar</string>

</array>


not including other jars when creating jar
comment  zipgroupfileset refid="lib.jars"

when the resource is the same location as execution file, how to set resource:
1. if execution file is jar(in jars/) , put resource in jars/ and use "java -jar" to run program
2. if execution file is App(in dist/), put resource in dist/  and run from xcode
3. place them in the bin/packageName/  


2008年6月24日 星期二

define macro in xcode

ex:
configuration: Debug
gcc 4.0 processing-> preprocessor macros:   _DEBUG

memory management in objective-c

retain:
increase retain count

release:
decrease retain count

array:
when an object is added to the array, the object's retain count is increased
when the array is deallocated,  the object( in array) 's retain count is decreased 

dealloc:
when an object's retain count becomes 0, its dealloc method is called

autorelease:
the object is added to autorelease pool when it is sent message autorelease
when the pool is drained, it sends message release to all objects in the pool

objects created by alloc, new, copy or mutableCopy have a retain count of 1 & are not in the autorelease pool 

if the object is get from other method, it is usually in the autorelease pool. If you do not want it to be deallocated when the pool drain, you must retain it

memory control for setter:
retain , then release
ex:
-(void)setName:(NSString*)name
{
      [name retain];
      [myName release];
      myName= name;
}

2008年6月23日 星期一

2008年6月18日 星期三

fileMerge

the GUI software to compare two files

compare two files
the two files compared are on the two top windows

use action to create merged file
the merged file is on the bottom window
(1) do action
(2) save file

diff

-w: ignore all whitespace

-q: Output only whether files differ

2008年6月16日 星期一

create application from jar

create  icon
use icon composer to create icon

use  jar bundler 
set jar files,  main class, icon pic

ex:
the created application is test.app
the executed file is:
test.app/Contents/MacOS/JavaApplicationStub 

2008年6月15日 星期日

NSObject

(id)init

(NSString*)description:
when NSLog print object, it will print the return value of description of the object


(BOOL)isEqual:(id)anObject
for NSString, isEqual will compare characters 
note: == compare if two objects are the same objects

NSString

start with @
ex:
NSString *test= @"hello";

NSString to C string
ex:
char *test = [ a UTF8String];

C string to NSString:
ex:
a= [NSString stringWithUTF8String:test];

NSLog

similar to printf in C
ex:
NSLog(@"hello");

token for NSLog:
%@: id

NSNumber

initWithInt


NSMutableArray & NSArray

NSArray:
objectAtIndex


NSMutableArray:
addObject:
ex:
[test addObject:dog1];

class and object

calling method:
ex:
[test run];
test is a object, run is its method

calling method with arguments:
ex:
[test run:1  secondArg:2];
1 is first argument,  2 is second argument, secondArg: is the description of second argument

create a object:
test = [NSMutableArray alloc];

create & init a object:
test = [  [NSMutableArray alloc] init];

TextField

setStringValue:
ex:
[textField setStringValue:@"hello"]

setIntValue:

setObjectValue:


import & objective-c keyword

#import:
similar to include. But it ensures the header is included only once.

keywords:
@end
@implementation
@class
@selector
@protocol
@property
@interface
@synthesize

type in objective-c

id:  a pointer to any type of object

BOOL::

YES: 1
NO: 0

IBOutlet:  a macro that evaluates to nothing. It is a hint for interface builder

IBAction:  the same as void,  a hint for interface builder

nil:  the same as NULL.  for pointers to objects
        In Objective-C, it is ok to send message to nil. The message is simply discarded.

interface builder and nib

the application's GUI is designed by interface builder

GUI is defined in the nib file.  

Use interface builder to open nib file & design gui

define class used in the nib
IBOutlet
instance variable points to other object is called outlet
ex:
IBOutlet  NSTextField *testField;
IBAction
the method is called by user interface objects
ex:
-(IBAction)seed:(id)sender;

create an object instance:
1. drag object from Library window to doc window
2. set its class to object's class name in the Identity Inspector

make connection:
connect two objects
ex:
a object has outlet textFiled of type TextField , then connect textFiled to  TextFiled GUI
ex:
when button b is pressed, it calls the method test in object c. Then connect b to object c's methods test

awakeFromNib:
all objects are sent the message awakeFromNib after the objects in nib file are brought to life
Hence, we can do something in awakeFromNib to init GUI



2008年6月11日 星期三

grep

find string in the file 
parameter:
-n:  show line number

ex:
grep -n  "rabbit"  test.rb

2008年6月10日 星期二

xcode debug

step over:
execute the function and move to the line after function

step into:
execute the function and move to the body of the function

step out:
originally in the function, execute the function and move to the line after function

continue:
continue program execution

2008年6月3日 星期二