[Info] BlocksKit

2011年11月14日月曜日 | Published in | 0 コメント


Foundation や UIKit ライブラリの様々なクラスのメソッドを blocks 化したライブラリ。 iOS 4.0+ 、 Mac OS X 10.6+ で利用可能。


What's In The Box

  • Performing blocks on an NSObject.
  • Key-value observation () with block handlers.
  • Associated objects in an Obj-C API. (Not directly block-related.)
  • NSArray, NSSet, NSDictionary, and NSIndexSet filtering and enumeration.
  • Macros for more quickly typing out the above.
  • NSInvocation creation using a block.
  • NSTimer block execution.
  • Both delegation and block callbacks on NSURLConnection.
  • Delegate callback for NSCache.

UIKit Extensions
  • UIAlertView, UIActionSheet with block callbacks and convenience methods.
  • Block initializers for UIControl and UIBarButtonItem
  • Block-backed initializers for UIGestureRecognizer.
  • On-touch utilities for UIView.
  • Block callbacks for MFMailComposeViewController and MFMessageComposeViewController.
  • Delegate alternative for UIWebView.
これはいい。ちょっとした処理を書くのにいちいちメソッドを起こさなくて済む。本来は Appleが提供して欲しいものだが。
リファレンスマニュアルが appledoc形式で提供されている。
BlocksKit Reference


UIActionSheet *testSheet = [UIActionSheet sheetWithTitle:@"Please select one."];
 [testSheet addButtonWithTitle:@"Zip" handler:^{ NSLog(@"Zip!"); }];
 [testSheet addButtonWithTitle:@"Zap" handler:^{ NSLog(@"Zap!"); }];
 [testSheet addButtonWithTitle:@"Zop" handler:^{ NSLog(@"Zop!"); }];
 [testSheet setDestructiveButtonWithTitle:@"No!" handler:^{ NSLog(@"Fine!"); }];
 [testSheet setCancelButtonWithTitle:nil handler:^{ NSLog(@"Never mind, then!"); }];
 [testSheet showInView:self.view];

[object performBlock:^(){
  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
} afterDelay:0.5f];

UIGestureRecognizer もある。
UITapGestureRecognizer *singleTap = [UITapGestureRecognizer recognizerWithHandler:^(id sender) {
     NSLog(@"Single tap.");
 } delay:0.18];
 [self addGestureRecognizer:singleTap];

- - - -


Leave a Response

人気の投稿(過去 30日間)