quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

NSScreencast Episode #102 Refactoring View Controllers

Refactoring View Controllers - NSScreencast

Twitterのフォロワーを一覧するアプリのリファクタリング

  • #import <Social/Social.h>
  • viewDidLoad has small lines of code eventually
  • refactoring
    • extract to new class
    • extract with new method (completion block etc.)
  • Add TwitterAccountStore class
    • requestAccessToAccountsWithType
    • (void (^)(ACAccount account, NSError error))completion
    • TwitterAccountStore.h
      • NS_ENUM(NSInteger, TwitterAccountStoreErrorCodes) {
        • TwitterAccountStoreNoAccountsError = 0,
        • TwitterAccountStoreAccessDeniedError
  • Add TwitterAPIClient class
    • extract url (followersURL)
    • extract params (followerParams)
    • (BOOL)successfulStatusCode:(NSInteger)statusCode {
      • return statusCode >= 200 && statusCode < 300;
    • dispatch_async(dispatch_get_main_queue(), ^{
      • completion(followerData[@"users"], nil);
      • completion(nil, jsonError);