Quantcast
Channel: HAPPY*TRAP » Objective-C
Browsing latest articles
Browse All 10 View Live

[Objective-C] 文字列を連結する

Objective-Cで文字列を連結する方法です。 2種類、紹介しておきますね。 stringByAppendingString1234NSString *str1 = @"こんにちは"; NSString *str2 = @"HAPPY*TRAPです"; NSString *result = [str1 stringByAppendingString:str2]; NSLog(@"%@",...

View Article


[Objective-C] カレントユーザのホームディレクトリのパスを取得する

カレントユーザのホームディレクトリのパスを取得する方法です。 NSHomeDirectoryメソッドを使います。12NSString *path = NSHomeDirectory(); NSLog(@"%@", path); 結果: /Users/machi 環境 OS X 10.8 Xcode 4.4

View Article


Image may be NSFW.
Clik here to view.

[Cocos2d] ‘sharedDispatcher’ is deprecatedと言われたときの対処方

cocos2d v2.0で、以下のように書いたらdeprecatedと言われちゃいました。 [CCTouchDispatcher sharedDispatcher] ‘sharedDispatcher’ is deprecated ccDeprecated.mを覗くと以下のようになっていますね。 @implementation CCTouchDispatcher (Deprecated)...

View Article

Image may be NSFW.
Clik here to view.

[Cocos2d] Sending ‘ClassName *’ to parameter of incompatible type...

cocos2d v2.0で、以下のように書いたらincompatible typeと言われちゃいました。 [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; ​Sending ‘ClassName *’ to parameter of...

View Article

Image may be NSFW.
Clik here to view.

[Cocoa] ウィンドウを閉じた時にアプリケーションを終了させる

Macアプリケーションで、ウィンドウを閉じた時にアプリケーションを終了させる方法です。 終了させたいNSApplicationオブジェクトのwindowWillCloseメソッドで、NSWindowオブジェクトが閉じたことを検知できます。1-(void)windowWillClose:(NSNotification *)aNotification;...

View Article


Image may be NSFW.
Clik here to view.

[Cocos2d] CCSpriteクラスのサブクラスを作る

cocos2dで、CCSpriteクラスのサブクラスを作る方法です。 例として、CCSpriteを継承したDogクラスを作成してみます。 Dog.h12345#import <Foundation/Foundation.h> #import "cocos2d.h" @interface Dog : CCSprite +(id)dog; @end...

View Article

Image may be NSFW.
Clik here to view.

[Cocos2d] タッチイベントを検知する

cocos2dで、タッチイベントを検知する方法です。 1.isTouchEnabledをYESに設定 SampleLayer.m12345678- (id)init {     self = [super init];     if (self) {         self.isTouchEnabled = YES;     }     return self; }...

View Article

Image may be NSFW.
Clik here to view.

[Cocos2d] 現在のSceneを取得する

cocos2dで、現在のSceneインスタンスを取得する方法です。 CCDirectorのrunningSceneメソッドで取得できました。1SampleScene *sampleScene = (SampleScene*)[[CCDirector sharedDirector] runningScene]; 環境 OS X 10.8 Xcode 4.4 cocos2d v2.0

View Article


Image may be NSFW.
Clik here to view.

[Cocos2d] シーンの背景色を設定する

cocos2dで、シーンの背景色を設定する方法です。 例では、CCLayerColorオブジェクトを作って、SceneにaddChildしています。 SampleScene.m123456789101112#import "SampleScene.h" @implementation SampleScene - (id)init {     self = [super init];     if...

View Article


Image may be NSFW.
Clik here to view.

[Objective-C] ARC使用時のFast Enumeration(高速列挙)で取り出した要素を変更する

ARC使用時に、以下のようにFast Enumeration(高速列挙)で取り出した要素を変更しようとしたらエラーで怒られました。 for (NSString *name in names) { name = @"hoge"; } Fast Enumeration Variables can’t be modified in ARC by default, declare the variable...

View Article
Browsing latest articles
Browse All 10 View Live