The Objective-C block utilities you always wish you had.

Related tags

Utility BlocksKit
Overview

BlocksKit

Blocks in C and Objective-C are downright magical. They make coding easier and potentially quicker, not to mention faster on the front end with multithreading and Grand Central Dispatch. BlocksKit hopes to facilitate this kind of programming by removing some of the annoying - and, in some cases, impeding - limits on coding with blocks.

BlocksKit is a framework for OS X Mountain Lion and newer, a static library for iOS 6 and iOS 7, and a framework for iOS 8 and newer.

BlocksKit was created by Zachary Waldowski and Alexsander Akers and is maintained by the former.

Installation

BlocksKit can be added to a project using CocoaPods. One may also use targets included in the project.

Framework

  • Download a release of BlocksKit.
  • Drag (or "Add Files...") BlocksKit.xcodeproj to your Xcode project using the Navigator.
  • From the "General" pane of your application or framework, add BlocksKit.framework to the "Embedded Binaries" list.
  • @import BlocksKit;

Static Library

  • Download a release of BlocksKit.
  • Run "Archive" in Xcode.
  • By default the static library will be compiled to ~/Library/Developer/Xcode/DerivedData.
  • Move libBlocksKit.a and Headers to your project's folder, preferably a subfolder like "Vendor".
  • In "Build Phases", Drag libBlocksKit.a into your target's "Link Binary With Libraries" build phase.
  • In the build settings of your target or project, change "Other Linker Flags" to -ObjC. Make sure your app is linked with CoreGraphics, Foundation, MessageUI, and UIKit.
  • Change (or add) to "Header Search Paths" the relative path to BlocksKit's headers, like $(SRCROOT)/Vendor/Headers.
  • Insert #import <BlocksKit/BlocksKit.h> in your project's prefix header.

Documentation

An Xcode-compatible documentation set is available from CocoaDocs.

License

BlocksKit is maintained under the MIT license. The project itself is free for use in any and all projects. You can use BlocksKit in any project, public or private, with or without attribution - though we prefer attribution! It helps us.

Unsure about your rights? Read more.

Individual credits for included code exist in the header files and documentation. We thank them for their contributions to the open source community.

Documentation help has been contributed by Alex Gray.

Comments
  • BlocksKit for arm64 architecture

    BlocksKit for arm64 architecture

    Hello,

    I've been trying to build the library with the latest Xcode 5, targeting iOS 7 and the 3 new default architectures "arm7 arm7s arm64". When doing so, libffi compilation fails with a bunch of errors, in the likes of

    In file included from /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/src/debug.c:26:
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/include/ffi_common.h:77:1: error: unknown type name 'ffi_status'
    ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
    ^
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/include/ffi_common.h:77:33: error: unknown type name 'ffi_cif'
    ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
                                    ^
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/include/ffi_common.h:78:1: error: unknown type name 'ffi_status'
    ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
    ^
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/include/ffi_common.h:78:37: error: unknown type name 'ffi_cif'
    ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
                                        ^
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/include/ffi_common.h:84:3: error: unknown type name 'ffi_cif'
      ffi_cif *cif;
      ^
    /Users/mathieudamours/Development/storm/iOS/Uptime/Pods/libffi/ios/src/debug.c:50:20: error: unknown type name 'ffi_type'
    void ffi_type_test(ffi_type *a, char *file, int line)
                       ^
    6 errors generated.
    

    When reverting to architectures "arm7 arm7s" it builds fine. Is that behavior expected?

    opened by matehat 54
  • KVO blocks API causing KVO crashes on object dealloc

    KVO blocks API causing KVO crashes on object dealloc

    First of all, thanks so much for BlocksKit. It's a real time saver!

    Now the problem: I've started using the KVO APIs (bk_addObserverForKeyPath:task:) and I'm getting some crashes when my objects are being dealloced:

    An instance 0xbbf42b0 of class MyClass was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
    

    I've spent some time trying to debug this. I'm fairly sure I got rid of all memory issues caused by reference cycles in blocks by doing the weakSelf/strongSelf dance. But this one is strange. The only observers on the objects in question are created by the objects themselves:

    __weak id weakSelf = self;
    
    [self bk_addObserverForKeyPath:@"property" task:^(id target) {
        MyClass* strongSelf = self;
        [strongSelf doSomething];
    }];
    

    Any ideas?

    opened by hartbit 16
  • exec bad access on 2.2.0

    exec bad access on 2.2.0

    I've recently updated xcode to 5.1 and BlocksKit from 2.0.0 to 2.2.0. I want to compile only for 32bit architectures.

    here it's my Podfile:

    platform :ios, '6.0'
    inhibit_all_warnings!
    pod 'BlocksKit', '2.2.0'
    pod 'SVProgressHUD'
    pod 'AFNetworking', '1.3.1'
    pod 'libextobjc/EXTScope', '~> 0.3'
    
    post_install do |installer|
        installer.project.targets.each do |target|
            target.build_configurations.each do |configuration|
                target.build_settings(configuration.name)['ARCHS'] = '$(ARCHS_STANDARD_32_BIT)'
            end
        end
    end
    

    and I've set the architecture of my project to ARCHS_STANDARD_32_BIT.

    since this my application start crashing with exec bad access. I've double checked and I haven't updated any other library. If I go back using '2.0.0' everything works perfectly again.

    basically 70% of the time I run the application the simulator (32 bit) the application crashes after 3-4 seconds.

    here is a screenshot of a crash: https://www.dropbox.com/s/955ji64hdhmdoe7/Screenshot%202014-03-15%2016.45.17.png here an other: https://www.dropbox.com/s/6c6k4mpec5xrv0c/Screenshot%202014-03-15%2016.46.57.png

    I've experienced the same happening in 2 other applications (same Podfile, same situation)

    I know that this is pretty generic, but which other information can I provide you?

    bug 
    opened by lucaquerella 15
  • Build without Cocoapods?

    Build without Cocoapods?

    I'm trying to avoid using CocoaPods and have the BK files directly in my Xcode project but I get build errors based on the use of brackets "<...>" in the BK internal imports. I've tried all header search paths possibilities I think ("user", "framework" and "library") both with and without "recursive". From what I read it seems that within a framework one should use quotes and the brackets are only for external frameworks. Is that correct? Any ideas?

    opened by Air-Craft 14
  • Use of super in categories

    Use of super in categories

    I'm pretty concerned by the use of:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesBegan:touches withEvent:event];
        BKTouchBlock block = [self associatedValueForKey:&kViewTouchDownBlockKey];
        if (block)
            block(touches, event);
    }
    

    In the UIView (BlocksKit) category. Just making sure everyone's aware that because this is in a category, super will send the message to UIView's superclass: UIResponder, and not to the original implementation of UIView's -touchesBegan:withEvent:. This is a problem because UIView might be doing important stuff in its -touchesBegan:withEvent: that could get completely bypassed by your implementation!

    I'm actually surprised clang doesn't freak out with a Category is implementing a method which will also be implemented by its primary class warning - I guess it's because it's UIResponder that implements the original method...

    In order to invoke the original implementation of -touchesBegan:withEvent:, you need to use Method Swizzling which has its own huge set of problems (not the least of which is the unpredictability when used with other libraries).

    I bring this up because I'm getting an unpredictable, random crash in my current application under iOS 6 in the simulator, where upon touching a UI element that results in a navigation controller push/pop, the runtime will inexplicably crash sometime shortly after in the same runloop cycle with a __sel_registerName EXC_BAD_ACCESS. I can't prove that it's definitely BlocksKit right now, but when I unlink BlocksKit, I no longer see the issue. It only happens under very specific conditions and it's very difficult to replicate reliably.

    Can someone tell me if I'm way off base here?

    bug 
    opened by tyrone-sudeium 14
  • BlocksKit iOS 1.5.2s unrecognized selector issue in Simulator Only

    BlocksKit iOS 1.5.2s unrecognized selector issue in Simulator Only

    I just upgraded to version 1.5.2s, adding ARMv7s support, but now i'm getting unrecognized selector errors being thrown when running in the simulator. Is anybody else seeing this? Nothing else in my project has changed and when I revert back to the 1.5.2 version, it works just fine again.

    Any thoughts?

    Thanks, James

    opened by jameshays 13
  • Warning in xcode5

    Warning in xcode5

    in libffi, I get these warnings /Users/Bryan/Documents/nevermore/Pods/libffi/ios/src/arm/ffi.c:325:21: Ambiguous expansion of macro 'alloca'

    but this won't happen in xocde4

    opened by BryanOne 12
  • Warning when using libBlocksKit.a

    Warning when using libBlocksKit.a

    I just started using BlocksKit (really, really, really, really, cool, thank you so much for your hard work, it saves me a lot of time when coding).

    Using it introduces a warning to my project, namely: 'warning: (armv7) /tmp/lto.o unable to open object file' After lots of Googling and efforts on my end to figure out what's going on, I've gotten as far as determining that if I turn on link time optimization for my target, the warning goes away, but it takes extremely long for builds to occur then.

    I read a post referencing the same warning on xcode-users, that suggested building the library without link time optimization. I thought I'd check to see if that would break anything on BlocksKit's end, since I'm in a bit over my head with this.

    Secondly, how can I get the iOS library built from the xcodeproj you provide? I cloned the repository, pulled the libffi submodule, but whenever I build the iOS library target, I'm not seeing anything produced.

    Below is the portion of the build log that generates the warning: GenerateDSYMFile /Users/jpo/Library/Developer/Xcode/DerivedData/Ambur-dujxvdthybskfsepytlscqnmqebi/Build/Products/Debug-iphoneos/Ambur.app.dSYM /Users/jpo/Library/Developer/Xcode/DerivedData/Ambur-dujxvdthybskfsepytlscqnmqebi/Build/Products/Debug-iphoneos/Ambur.app/Ambur cd "/Users/jpo/Desktop/Ambur code" setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/jpo/Library/Developer/Xcode/DerivedData/Ambur-dujxvdthybskfsepytlscqnmqebi/Build/Products/Debug-iphoneos/Ambur.app/Ambur -o /Users/jpo/Library/Developer/Xcode/DerivedData/Ambur-dujxvdthybskfsepytlscqnmqebi/Build/Products/Debug-iphoneos/Ambur.app.dSYM

    bug 
    opened by jpohhh 12
  • Crash on device with UIActionSheet blocks

    Crash on device with UIActionSheet blocks

    Hi,

    when I paste the UIActionSheet example (http://dizzytechnology.com/data/BlocksKit/Categories/UIActionSheet+BlocksKit.html) to my code it works well in the simulator, but on the device (latest iOS 5) the app freezes. This is the console output:

    warning: check_safe_call: could not restore current frame
    
    warning: Unable to restore previously selected frame.
    

    and this is the backtrace:

    (gdb) bt
    #0  0x00000000 in ?? ()
    

    Any idea?

    opened by Shukuyen 12
  • Using BlocksKit with MPVolumeView showing route button causes crash

    Using BlocksKit with MPVolumeView showing route button causes crash

    If you use BlocksKit in your project, and you also use an MPVolumeView that is displaying a "route" button (allows you to select AirPlay destination for playing audio), tapping the route button will cause a crash.

    The crash references an unrecognized selector associatedValueForKey on an internal MPVolumeView action sheet subclass. Either BlocksKit's associatedValueForKey: is conflicting with Apple's own internal implementation, or else that particular action sheet subclass declares its own addButtonWithTitle:handler: method that BocksKit is unintentionally overriding with its category.

    opened by adamjernst 12
  • iOS 8 UIActionSheet Crash

    iOS 8 UIActionSheet Crash

    Setting a block to the properties commented below will cause a crash.

    UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"Test"];
    
    // These are fine.
    [actionSheet bk_addButtonWithTitle:@"Test1" handler:^{ NSLog(@"Test1"); }];
    [actionSheet bk_addButtonWithTitle:@"Test2" handler:^{ NSLog(@"Test2"); }];
    [actionSheet bk_addButtonWithTitle:@"Test3" handler:^{ NSLog(@"Test3"); }];
    [actionSheet bk_setCancelButtonWithTitle:@"Cancel" handler:^{ NSLog(@"Cancel"); }];
    [actionSheet bk_setCancelBlock:^{ NSLog(@"Cancel Block"); }];
    
    // Any of these will crash.
    [actionSheet bk_setWillShowBlock:^(UIActionSheet *actionSheet) { NSLog(@"Will Show Block"); }];
    [actionSheet bk_setDidShowBlock:^(UIActionSheet *actionSheet) { NSLog(@"Did Show Block"); }];
    [actionSheet bk_setWillDismissBlock:^(UIActionSheet *actionSheet, NSInteger index) { NSLog(@"Will Dismiss Block"); }];
    [actionSheet bk_setDidDismissBlock:^(UIActionSheet *actionSheet, NSInteger index) { NSLog(@"Did Dismiss Block"); }];
    

    Here is the crash.

    -[UIActionSheet bk_setWillShowBlock:]: unrecognized selector sent to instance
    
    opened by jwutke 11
  • UIAlertView+BlocksKit crash

    UIAlertView+BlocksKit crash

    when use uitextview and try to limit the count of character by reset the text in textViewDidChange method ,crash happen if you type to the max count then shake to undo ,click confirm

    crash come to - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;line 94 [realDelegate alertView:alertView clickedButtonAtIndex:buttonIndex];

    error msg is [NSBigMutableString substringWithRange:]: Range {19, 6} out of bounds; string length 19 (null)

    opened by miku1958 0
  • The UIView+Blockkit.m, in 27 line, has one error.

    The UIView+Blockkit.m, in 27 line, has one error.

    The 27 line code: BOOL rightTaps = (tap.numberOfTapsRequired == numberOfTaps); should be : BOOL rightTaps = (tap.numberOfTapsRequired < numberOfTaps); and then 29 line change to: [tap requireGestureRecognizerToFail:gesture];

    opened by iWECon 1
  • BlocksKit UIEditUserWordController causes A2DynamicDelegate UITextField+BlocksKit crash

    BlocksKit UIEditUserWordController causes A2DynamicDelegate UITextField+BlocksKit crash

    BlocksKit UIEditUserWordController causes A2DynamicDelegate UITextField+BlocksKit crash Chinese Chinese Chinese Chinese Chinese Chinese

    http://blog.csdn.net/Sico2Sico/article/details/54969950

    opened by ahahe 1
Releases(v2.2.5)
Owner
BlocksKit
BlocksKit
Lightweight utilities for making OSLog more pleasant

UnifiedLoggingPlus Lightweight utilities for making OSLog more pleasant. Integration Swift Package Manager

Chime 10 Oct 26, 2022
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 1, 2023
Catch Objective-C exceptions in Swift

ExceptionCatcher Catch Objective-C exceptions in Swift There are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (NSKeyedUnar

Sindre Sorhus 98 Nov 23, 2022
💡 A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Tim Oliver 3 May 23, 2021
Reflection for enumerations in Objective-C.

ReflectableEnum A macro and a set of functions introducing reflection for enumerations in Objective-C. Features: get a string value for an enumeration

Arek Holko 333 Nov 17, 2022
Because Objective-C should have inherited more from Smalltalk

OpinionatedC Sometimes, Objective-C is just overly verbose. Life is too short to enumerateObjectsUsingBlock and who has the time to create sub-arrays

Leo Schweizer 52 Apr 7, 2022
A Cocoa library to extend the Objective-C programming language.

The Extended Objective-C library extends the dynamism of the Objective-C programming language to support additional patterns present in other programm

Justin Spahr-Summers 4.5k Dec 30, 2022
Proper YAML support for Objective-C. Based on recommended libyaml.

YAML.framework for Objective-C Based on C LibYAML library (http://pyyaml.org/wiki/LibYAML) by Kirill Simonov. YAML.framework provides support for YAML

Mirek Rusin 236 Aug 29, 2022
Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

Abdullah Selek 22 Jun 18, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
A quick and "lean" way to swizzle methods for your Objective-C development needs.

Swizzlean A quick and "lean" way to swizzle methods for your Objective-C development needs. Adding Swizzlean to your project Cocoapods CocoaPods is th

Ryan Baumbach 104 Oct 11, 2022
Data Mapping library for Objective C

OCMapper is a data mapping library for Objective C that converts NSDictionary to NSObject

Aryan Ghassemi 346 Dec 8, 2022
Pavel Surový 0 Jan 1, 2022
Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm. Creating a chan

Christoffer Winterkvist 127 Jun 3, 2022
Ethereum Wallet Toolkit for iOS - You can implement an Ethereum wallet without a server and blockchain knowledge.

Introduction EtherWalletKit is an Ethereum Wallet Toolkit for iOS. I hope cryptocurrency and decentralized token economy become more widely adapted. H

Sung Woo Chang 136 Dec 25, 2022
LifetimeTracker can surface retain cycle / memory issues right as you develop your application

LifetimeTracker Bar style Circular style LifetimeTracker can surface retain cycle / memory issues right as you develop your application, and it will s

Krzysztof Zabłocki 2.8k Jan 4, 2023