显示标签为“Mac”的博文。显示所有博文
显示标签为“Mac”的博文。显示所有博文

2009年11月18日星期三

Objective-C 學習筆記

最近正在學習iPhone 開發,記錄一下

常用 Key words

. Messaging
. Import Syntax
. Declaring Method Headers
. Inheritance Synax
. property and synthesize  keywords
. interface and implementation Declarations
. protocols
. self keywords.
. Id keyword

Messaging:  --可以理解為method (c/c++/java)
Example:
[object message]; 
similar to :
object.method();
object->method();

Messaging with parameters

Example: 含參數的例子
[object message: param1  withParameter:param2];
Similar to:
object.method(param1, param2);
object->method(param1,param2);


Nestd Messages :

example:嵌套調用
[object secondMessage:[object message]]
Similar to :
object.secondMessage(object.message());
object.secondMessage(object->message());

The import statement
example:
#import <Library.h>
#import "class.h"
Similar to include and import statement in  C/C++/Java and no include guards required with Objective-C imports

Method Headers
Example:
-(returnType)methodName:(dataType) param1  //對象方法聲明
Called by:
[object methodName:param1] //對象方法調用
a + rather than - before the method signifies that the method is static  //"+"表示靜態方法(class的方法) "-"表示 對象的方法
Similar to :
returnType methodName(dataType param1)

Declaring Inheritance //繼承關係
example:
ClassName:ParentClass<Protocol>
Similar to:
ClassName:ParentClass<Interface>
ClassName  extends ParentClass implements interface
Note:
There is no mulitiple inheritance in Objective-C //Objective-C 中不存在多繼承


@property declaration
Used to create getters and setters for to specified variable. Place in the implementation of a class   //感覺是getter和setter的一個省事的做法
Example:
@property dataType variablename //在*.h文件中declare 在*.m文件中使用@synthesize與之對應


typical usage of variables defined using @property:
className.variable = value
variable = className.variable

@interface
Declare class member variables, and methods in the interface // @interface 作用是聲明類的變量和方法


@interface ClassName: ParentClass <Protocol>
{
    dataType variableName;
}
@property data;
-(returnType)methodName:(dataType)param1
@end


@synthesize
Used to synthesize the getter and setter declared with the @property directive //與@property對應
example:
@synthesize variableName


@implementation
This is where you implement the actual class.  //具體實現一個類,或者是類的實現


@implementation ClassName
@synthesize data;
-(returnType)methodName:(dataType)param1
{
    ....Method Details...
}
@end


Protocols
implemented using <> brackets when creating class interface //在創建interface的時候使用的
example:
@interface ClassName:ParentClass <Protocol>
similar to interface in Java, and C++ //類似Java C++的interface/abstract class 的實現


Self Keyword
Example:
[self message]
similar to :
the this keyword used in Java and C++.
Self must be used when calling a non-static method within the same object // self只能調用非靜態的方法


id keyword
The id keyword is used as generic identifier to identify any class
Similar to the Object keyword in java and  to void pointer(void*) in C++ //我的理解是最泛的一個標識

記錄一下,備忘!

2009年11月10日星期二

max os 上使用的 VNC VIEWER Chicken of the VNC 不錯

昨天參加一個WORKSHOP,要求用VNC登錄AMAZON'S EC的CLOUD, 要求有一個VNC CLIENT,在MAC 上不知道內置有沒有,情急之下,決定下載一個
GOOGLE之, 發現一個 http://sourceforge.net/projects/cotvnc/
Chicken of the VNC
free的, 趕緊DOWNLOAD下來,測試一下, 還不錯用起來.

另外體驗了一下 AMAZON'S CLOUD, EC2
http://aws.amazon.com/ec2/
據說是收費的, 好像$2/HOURS,看來AMAZON已經走到CLOUD裡面去了,通過VNC體驗了一下CLOUD :)

2009年11月3日星期二

2009年9月30日星期三

xcode下開發1

因公司要做iPhone版本的一個產品,所以需要使用xcode這個東西,經過兩天的折騰,終於寫了個HelloWorld出來,對object c也有了初步的認識

這裡使用的是xcode3.0版本,參考 (Jailbreak Goddess) Erica Sadum 提供了大量的代碼,我是比較愚鈍的,進展很慢:(,不過終於搞好了以一個hello world
為了閱讀方便,作者把所有的代碼寫到一起了
---------------main.c------------------------
#import

@class UIImageView;

@interface HelloController : UIViewController
{
UIImageView *contentView;
}
@end

@implementation HelloController
- (id)init
{
if (self = [super init])
{
self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
// place any further initialization here
}
return self;
}

/**
*建立起主要的應用程序VIEW
**/
- (void)loadView
{
// Load an application image and set it as the primary view
contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setImage:[UIImage imageNamed: @"helloworld.png" ]];

// Provide support for auto-rotation and resizing
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

// Assign the view to the view controller
self.view = contentView;
[contentView release]; // reduce retain count by one

}

// Allow the view to respond to iPhone Orientation changes
/**
* 為自動旋轉功能准備幾個標志
**/
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

-(void) dealloc
{
// add any further clean-up here
[contentView release];
[super dealloc];
}
@end

/**
* UIApplicationMain()呼叫跑到這裡了
**/
@interface SampleAppDelegate : NSObject {
}
@end

@implementation SampleAppDelegate

// On launch, create a basic window
/**
* applicationDidFinishLaunching: 方法
*標准的mainScreen繪制一個新視窗, 它會建立一個導覽控制程序,並知道給一個新的HelloController(UIViewControler子類別)來當作他自己的根源試圖控制程序(Root View Controller)
**/
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[HelloController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application {
// handle any final state matters here
}

- (void)dealloc {
[super dealloc];
}

@end


/**
main函數是xcode自動產生的,而且還保持未經過人變動的原貌
他呼叫 UIApplicationMain(),並將主要的應用程序的委派方法名稱,這裡是 @"SampleAppDelegate"傳給他!
*/

int main(int argc, char *argv[])
{
/**
*這裡應該是內存分配
**/
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
printf("hellowrold\n");
int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");
[pool release];
return retVal;
}

---------------------------------------------
我創建了一個新的PROJECT,然後把上面的代碼copy過去,運行是報錯.屢試不爽.
後來按照書中的要求一步步來,就沒有出錯了,環境不熟悉阿:
記錄一下:
1 刪除classes 文件夾
2 刪除.xib文件
3 在info.list,我的版本上是helloworld-info.list文件中的"NSMainNibFile"的KEY-VALUE 這一行
4 加入image文件夾,這裡是用ADD NEW GROUP
5 拖文件到這個文件夾中(xcode環境中)
6 用上面的main.m覆蓋原來的內容
7 COMMONAD + ENTER 運行模擬器
如果沒有問題的話就OK了

這裡有幾個小技巧:
COMMAND + <
COMMAND + > 模仿IPHONE橫位

COMMAND + SHIHF + R 可以看到後台運行的情況, 我原來一直不知道printf打LOG信息從那裡看,這下子就知道了:)

INSTRUMENTS的執行方式: instruments是APPLE基於SUN的DTRACE搞的,一直很向往之,終於見識了,設定方法:
XCODE環境 -->RUN --> START WITH PERFORMANCE TOOL ,有幾個方式, 我猜OBJECT ALLOCATION 和 CPU SAMPLER應該是比較常用的. 估計以後查內存洩露的時候可以用到.




2009年9月16日星期三

MAC OS 上删除QIM/IMKQIM

一直使用MAC自帶的中文輸入感覺好慢,原來查過,沒有很好的中文系統,當時是10.4,重裝之後,昨天突然想起來了,能不能提高一下效率,果然有了:
QIM FOR搜狗,下載之安裝上了,心存疑慮,我下的是不是最新版呢,繼續GOOGLE,發現最新的是IMKQIM1.7了,下載之,怎麼用呢?
有用了幾分鍾在本子上照阿找,找到了,就是"多國語言"那裡,勾上即可.

再有疑問?是不是免費的,繼續GOOGLE發現確實要收費,唉,卸載之!!怎麼卸載是一個問題!!!

繼續GOOGLE,發現有免費的FIT
http://fit.coollittlethings.com/
下載之,安裝上了,現在這個用起來還是不錯的,呵呵!
以後再MAC上干活就用他了

如何卸載PIM呢?GOOGLE之
http://terrywang.net/archives/595 寫的不錯,摘錄之:

1.4.5的dmg中的文档带了如何删除的方法

请按照下面步骤删除QIM:
1. 首先在输入法菜单里取消QIM
2. 然后关闭所有当前使用过QIM的程序
3. 进入/Library/Components目录
4. 删除QIM.component
5. 重新登录即可完全删除QIM,QIM在~/Library/QIM目录里保存有用户的一些自定义信息和词库,如果用户不想保留,可以删除这个目录。


删除IMKQIM 1.6的具体步骤:
1. 首先在输入法菜单里取消QIM
2. 然后关闭所有当前使用过QIM的程序
3. 进入/Library/Input Methods目录
4. 删除IMKQIM.app
5. 重新登录即可完全删除QIM,QIM在~/Library/QIM目录里保存有用户的一些自定义信息和词库,如果用户不想保留,可以删除这个目录。

依法操作,果然刪除干淨了!
此文就是用FIT寫得,還支持繁體!!!
記錄一下,備查!


2009年8月31日星期一

Mac下的bloger editor test

不得不承认自己的愚钝,这么好的思想不会用,在windows下面使用的是windows live writer决的不错,干活很高效,想mac下面也应该有把,果不其然,MarsEdit, ecto, 等等,试用一下MarsEdit先。

2009年6月19日星期五

Object-C StudyNote-1

Method:
.. Behavior associated with an object

-(NSString *) name
{
// implementation
}
-(void)setName:(NSString *) name
{
//implementation
}

selector --有点引用的意思
. name for referring to a method
. include colons to indicate arguments
. Doesn't actually include arguments or indicate types
SEL mySelector = @selector(name);
SEL anotherSelector = @selector(setName:);
SEL lastSelector = @selector(doStuff:withThing:andThing:);

Message
. the act of performing a selector on an object
. with arguments, if necessary
NSString * name = [myPerson name];
[myPerson setName:@"New Name"];