今週の週刊 Life is Beautiful:8月21日号
私にとってのブログと有料メルマガの違い

ザッカーバーグの面接試験2:アクティビティ・インディケーター

先日の「ザッカーバーグの面接試験:Objective-C のブロックを使いこなす」には数多くの答えをいただいたので、それに気を良くして第二問。これも iOS 用だが、先の問題と違い、この問題は初級者〜中級者向けだ。

[問題]

iOS ではステータスバー上のアクティビティ・インディケーターの ON/OFF は、[UIApplication sharedApplication] の networkActivityIndicatorVisible プロパティに YES/NO をセットすることにより行います。そのため、複数の非同期通信を同時に行うアプリケーションの場合、少なくとも一つの非同期通信が行われている時だけ YES にする仕組みを作る必要があります。

そこで、NetworkActivityManager というシングルトン・クラス(インスタンスを一個しか持たないクラス)を作り、非同期通信中はそのシングルトンへの strong reference を保持する、という規約でアクティビティ・インディケーターをコントロールすることにしました。

使い方は、非同期通信の開始時期に、

    self.activity = [NetworkActivityManager sharedInstance]; // activity は strong reference

と strong reference を保持し、非同期通信の終了(もしくはキャンセル時)に

    self.activity = nil;

とリリースします。

さてここで問題です。NetworkActivityManager クラスを可能なかぎりシンプルに実装してください。また、このケースで、シングルトンへのstrong referenceを使う利点と欠点を述べてください。

制限時間:15分

 

 

 

 

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name is required. Email address will not be displayed with the comment.)