[iOS] Asynchronous Library in Objective-C

I made a asynchronous library in Objective-C.
Here is Project file.

What is this ?

Asynchronous library is one of the CommandPettern.
Set a command, and execute it.
Then it can call method asynchronously.

Class Explanation

Command > Base class
WaitCommand > timer class
FunctionCommand > function class
SerialCommand > it call registered methods sequentially
ParallelCommand > it call registered methods at the same time

Inspired from
These ActionScript 3 libraries in Japan.
Commands (@fladdict)
Progression(@nium)

How to use

First, you copy below picture files.

WaitCommand test

- (void)commandCompleteHandler:(NSNotification *)aNotification
{
	NSLog(@"command complete !");
}

- (void)waitCommandTest
{
	WaitCommand *wc = [[WaitCommand alloc] initWithTime:1.0];
	[wc addEventListener:kCommandEventCommandComplete target:self listener:@selector(commandCompleteHandler:)];
	[wc execute];
	[wc release];
}

FunctionCommand test

- (void)commandCompleteHandler:(NSNotification *)aNotification
{
	NSLog(@"command complete !");
}

- (void)testFunction
{
	NSLog(@"test function");
}

- (void)functionCommandTest
{
	FunctionCommand *fc = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction)];
	[fc addEventListener:kCommandEventCommandComplete target:self listener:@selector(commandCompleteHandler:)];
	[fc execute];
	[fc release];
}

SerialCommand test

- (void)commandCompleteHandler:(NSNotification *)aNotification
{
	NSLog(@"command complete !");
}

- (void)testFunction
{
	NSLog(@"test function");
}

- (void)serialCommandTest
{
	SerialCommand *sc = [[SerialCommand alloc] init];
	WaitCommand *wc = [[WaitCommand alloc] initWithTime:1.5];
	FunctionCommand *fc = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction)];
	
	[sc addCommand:wc];
	[sc addCommand:fc];
	[sc addEventListener:kCommandEventCommandComplete target:self listener:@selector(commandCompleteHandler:)];
	[sc execute];

	[wc release];
	[fc release];
}

ParallelCommand test

- (void)commandCompleteHandler:(NSNotification *)aNotification
{
	NSLog(@"command complete !");
}

- (void)testFunction
{
	NSLog(@"test function");
}

- (void)parallelCommandTest
{
	ParallelCommand *pc = [[ParallelCommand alloc] init];
	WaitCommand *wc = [[WaitCommand alloc] initWithTime:1.5];
	FunctionCommand *fc = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction)];
	
	[pc addCommand:wc];
	[pc addCommand:fc];
	[pc addEventListener:kCommandEventCommandComplete target:self listener:@selector(commandCompleteHandler:)];
	[pc execute];

	[wc release];
	[fc release];
}

PrallelCommand and SerialCommand Mixed test

- (void)commandCompleteHandler:(NSNotification *)aNotification
{
	NSLog(@"command complete !");
}

- (void)testFunction
{
	NSLog(@"test function");
}

- (void)testFunction2:(id)arg1
{
	NSLog(@"testFunction 2, arg1 = %@", arg1);
}

- (void)testFunction3:(id)arg1 arg2:(id)arg2
{
	NSLog(@"testFunction 2, arg1 = %@, arg2 = %@", arg1, arg2);
}

- (void)parallelSerialMixedTest
{
	ParallelCommand *pc = [[ParallelCommand alloc] init];
	WaitCommand *wc = [[WaitCommand alloc] initWithTime:1.5];
	FunctionCommand *fc = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction)];
	FunctionCommand *fc2 = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction2:) withObject:[UIColor blueColor]];
	UIViewController *vc = [[UIViewController alloc] init];
	FunctionCommand *fc3 = [[FunctionCommand alloc] initWithTarget:self selector:@selector(testFunction3:arg2:) withObject:@"Hello command !" withObject:vc];
	[vc release];
	WaitCommand *wc2 = [[WaitCommand alloc] initWithTime:1.0];
	SerialCommand *sc = [[SerialCommand alloc] init];
	[pc addCommand:fc];
	[pc addCommand:fc2];
	[pc addCommand:fc3];
	
	[sc addCommand:wc];
	[sc addCommand:fc];
	[sc addCommand:wc2];
	[sc addCommand:pc];
	
	[sc addEventListener:kCommandEventCommandComplete target:self listener:@selector(commandCompleteHandler:)];
	[sc execute];
	
	[pc release];
	[wc release];
	[fc release];
	[fc2 release];
	[fc3 release];
	[wc2 release];
}

Tags: ,

2 Responses to “[iOS] Asynchronous Library in Objective-C”

  1. Hi Tasuku great job.
    My name is Fernando from Brazil, i’m will travel to Japan in next year, and i a need tips for jobs with Objective-C for mobile development (iPhone and iPad) and Android. I will like to make contact with people with a objective to make friends and profissional contacts. Please contact me in my gtalk or msn ferbass at gmail.com

    Thank in advanced

    FerBass

  2. Ferunando, thank you for your comment.
    If you come to Japan in next year,
    I will introduce my programmer friends to you.

    When will you come to Japan ?
    Would you tell me its month ?
    I will prepare the meeting.

    Thanks.