Latest 1.2.1
Homepage https://github.com/seivan/SHControlBlocks
License MIT
Platforms ios 6.0, requires ARC
Authors

CI Status
Version
Platform
License

This pod is used by SHUIKitBlocks as part of many components covering to plug the holes missing from Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application’s architecture.

Overview

The blocks and events are automatically removed once their control is gone, so it isn’t necessary to clean up – Swizzle Free(™)

API

Creating

Removing

Helpers and Properties

USAGE

Creating

Removing

Helpers and Properties

Installation

pod 'SHControlBlocks'

Setup

Put this either in specific files or your project prefix file

#import "UIControl+SHControlBlocks.h"

or

#import "SHControlBlocks.h"

API

Creating

#pragma mark -
#pragma mark Add block
-(void)SH_addControlEvents:(UIControlEvents)controlEvents
                 withBlock:(SHControlEventBlock)theBlock;

-(void)SH_addControlEventTouchUpInsideWithBlock:(SHControlEventBlock)theBlock;

Removing

#pragma mark -
#pragma mark Remove block
-(void)SH_removeControlEventTouchUpInside;
-(void)SH_removeBlocksForControlEvents:(UIControlEvents)controlEvents;
-(void)SH_removeControlEventsForBlock:(SHControlEventBlock)theBlock;
-(void)SH_removeAllControlEventsBlocks;

Helpers and Properties

#pragma mark -
#pragma mark Helpers
-(NSSet *)SH_blocksForControlEvents:(UIControlEvents)theControlEvents;
-(NSSet *)SH_controlEventsForBlock:(SHControlEventBlock)theBlock;

#pragma mark -
#pragma mark Properties

#pragma mark -
#pragma mark Getters
@property(nonatomic,readonly) BOOL SH_isTouchUpInsideEnabled;

@property(nonatomic,readonly) NSDictionary * SH_controlBlocks;

Usage

Creating

With SHControlBlocks you can set auto-removed blocks instead of using selectors

  [self.btnFirst SH_addControlEvents:UIControlEventTouchDown withBlock:^(UIControl *sender) {
    [weakSelf performSegueWithIdentifier:@"second" sender:nil];
    NSLog(@"first");
  }];

or if you want add additional blocks

  [btnSecond SH_addControlEvents:UIControlEventTouchUpInside withBlock:counterBlock];
  [btnSecond SH_addControlEvents:UIControlEventTouchDown withBlock:counterBlock];

Convenience selector for touchUpInside

  ; //this will also remove the block :)
  }];

Removing

Remove specific blocks – will also remove the Event from the target if it was the last block

  [btnSecond SH_removeControlEventsForBlock:counterBlock];

Remove specific events

  [btnSecond SH_removeBlocksForControlEvents:UIControlEventTouchUpInside];
  [btnSecond SH_removeControlEventTouchUpInside];

Remove all blocks and events

  ;

Helpers and Properties


  ;
  ;
  ;

  NSSet * controlBlocks = button.SH_controlBlocks[@(UIControlEventTouchUpInside)];  
  NSAssert(button.SH_isTouchUpInsideEnabled,    @"Touch up inside should be enabled");
  NSAssert(button.SH_controlBlocks.count  == 1, @"There should be one event");
  NSAssert(controlBlocks.count            == 3, @"There should be three blocks");

Contact

If you end up using SHControlBlocks in a project, I’d love to hear about it.

email: [email protected]
twitter: @seivanheidari

License

SHControlBlocks is © 2013 Seivan and may be freely
distributed under the MIT license.
See the LICENSE.md file.

Latest podspec

{
    "name": "SHControlBlocks",
    "version": "1.2.1",
    "summary": "Prefixed UIControl category with blocks, auto-removed. Swizzle free!",
    "description": "n                    UIControl events with blocks.n                    Blocks are hold with a weak reference so you don't have to cleanup when your object is gone.n  n                    * Swizzle and junk freen                    * No need to clean up after - The control blocks are self maintained.n                    * Controls are referenced in a map with weak propertiesn                    * Auto remove control from outlets and all actions when removing all the blocksn                    * Prefixed selectors.n                    * Minimum clutter on top of the public interface.n                    n",
    "homepage": "https://github.com/seivan/SHControlBlocks",
    "license": "MIT",
    "authors": {
        "Seivan Heidari": "[email protected]"
    },
    "source": {
        "git": "https://github.com/seivan/SHControlBlocks.git",
        "tag": "1.2.1"
    },
    "platforms": {
        "ios": "6.0"
    },
    "source_files": "SHControlBlocks/**/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This