メインページ
提供: Studying Cocoa
シンプルなサンプルコード作成を目的とした、Cocoa学習のためのリファレンスを目指しています。 Xcodeのデベロッパドキュメントをベースにしています。
目次 |
開発環境
| OS | Mac OS X 10.6.2 (Snow Leopard) |
| Xcodeバージョン | バージョン 3.2.1 |
| gcc | version 4.2.1 (Apple Inc. build 5646) (dot 1) |
Hello World!
/*** hello_world.m* $gcc -framework Foundation hello_world.m -o hello_world*/#import <Foundation/NSObject.h>#import <Foundation/NSString.h>@interface HelloWorld : NSObject
{NSString* message;
}- (NSString *) message;
- (void) say:(NSString *)msg;
@end@implementation HelloWorld- (NSString *) message {
return message;}- (void) say:(NSString *)msg {
NSLog(@"%@", msg);
}@endint main(){
HelloWorld *helloWorld = [[HelloWorld alloc] init];
[helloWorld say:@"Hello World!"];
[helloWorld release];
return 0;
}
コマンドラインツールのスケルトン
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // insert code here... NSLog(@"Hello, World!"); [pool drain]; return 0; }
GCCでのビルド
$gcc -o 出力ファイル -framework フレームワーク(Foundationなど) ソースファイル(source.mなど)
デバッグライト
NSLog( @"%@", someObject );
class-dumpコマンド
download & install
- ビルド済:<http://www.codethecode.com/projects/class-dump/>
- githubにもある:<https://github.com/nygard/class-dump>
Usage
class-dump 3.1.2 Usage: class-dump [options] <mach-o-file> オプションは以下の通り: -a インスタンス変数のオフセット値を表示 -A 実装メソッドのアドレスを表示 --arch <arch> ユニバーサルバイナリーからアーキテクチャ(ppc, ppc7400, ppc64, i386, x86_64, etc.)を指定して選択 -C <regex> 正規表現にマッチしたクラスだけを表示 -f <str> メソッド名を検索 -H カレントディレクトリまたは、-oオプションで指定したディレクトリにヘッダーファイルを作成する -I クラス、カテゴリ、プロトコルを継承クラス名で並べ替え(上書きは-sコマンド) -o <dir> -Hオプションで使うための出力ディレクトリを指定 -r recursively expand frameworks and fixed VM shared libraries -s クラスとカテゴリを名前で並べ替え -S メソッドを名前で並べ替え -t テストのためにヘッダー出力をしない --list-arches アーキテクチャ一覧を出力する
Darwinソースコード
Xcode Workflow Tutorial
Xcodeを使ったHello Worldアプリケーションの作成チュートリアル。 Xcodeのアプリ作成フローを学べる。