BlockParty 1.1.0

BlockParty 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年5月

Andrew McKnight维护。



  • 作者:
  • Andrew McKnight

Block Party!

乐高式的代理模式。

反代理化

使用BlockParty来替换所有的代理回调为块(或者只是部分--所有的代理回调在所有情况下仍然被触发)。

Core Bluetooth(CBCentralManager,CBPeripheral和CBPeripheralManager)

CBPeripheralManager
[self.peripheralManager prt_peripheralManagerIsReadyToUpdateSubscribersHandler:
  ^(CBPeripheralManager* manager) {
    [self sendData];
  }];
CBPeripheral
[peripheral prt_discoverServices:services
                      completion:^(CBPeripheral* peripheral, NSError* error) {
                        if (error) {
                          NSLog(@"error discovering services %@", error);
                        } else {
                          for (CBService* service in peripheral.services) {
                            if ([service.UUID.UUIDString isEqualToString:TRANSFER_SERVICE_UUID]) {
                              self.foundService = service;
                              NSArray *characteristics = @[ [CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID] ];
                              [self.peripheral discoverCharacteristics:characteristics
                                                            forService:self.foundService];
                              break;
                            }
                          }
                        } 
                      }];

UINavigationController

[self.navigationController prt_pushViewController:someViewController
      animated:YES
      preparation:^(UINavigationController *navigationController,
                    UIViewController *presentingViewController) {
        NSLog(@"Hi! I execute before the nav push!");
      }
      completion:^(UINavigationController *navigationController,
                   UIViewController *presentedViewController,
                   NSArray *poppedViewControllers) {
        NSLog(@"Hi! I execute after the nav push!");
      }];

工具

PRTAssert

在开发期间想要一个立即失败的断言以及在生产中优雅退出的功能吗?如果您曾经写过类似下面这样的代码

NSAssert(expression, @"something went wrong");
if (expression) {
  NSLog(@"production success code");
} else {
  NSLog(@"production failure code");
}

那么您可以使用这个工具宏来结合assert和条件

PRTAssert(expression,
          ^{ NSLog(@"production success code"); },
          ^{ NSLog(@"production failure code"); },
          @"something went wrong")