Latest 0.1.6
License MIT
Platforms watchos 2.0, ios 8.0, osx 10.9, tvos 9.0

[![CI Status]( Otasevic/RHBCastingObjC.svg?style=flat)]( Otasevic/RHBCastingObjC)


This mini library will make your code safer and more readable when you deal with casting. This kind of library is not needed for Swift, because Swift will force you to write safe and readable casting code out of the box.


So, instead of doing it standard way, like:

if ([self.collection isKindOfClass:[NSArray class]]) {
    NSArray *array = (NSArray *)self.collection;
    /// ... some other code

This pod enables you to do the following:

NSArray *array = [NSArray rhb_dynamicCast:self.collection];
if (array) {
    /// ... some other code

Note that self.collection is actually duplicated code in the standard approach, and it may have performance impacts if its created on the fly.

Method rhb_dynamicCast: uses isKindOfClass: internally. There is another method named rhb_strictDynamicCast: that uses isMemberOfClass: internally.


To make extra security checks during development (asserts) then one should use the following:

NSArray *array = [NSArray rhb_verifyCast:self.collection];

instead of standard way:

NSArray *array = (NSArray *)self.collection;

First way will do the assertion and check if the cast is valid in debug mode to prevent errors during development. Both ways will have the same effect in release mode.


RHBCastingObjC is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "RHBCastingObjC"


Lazar Otasevic, [email protected]


RHBCastingObjC is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "RHBCastingObjC",
    "version": "0.1.6",
    "summary": "Safe casting category.",
    "description": "Red Hot Bits safe casting category.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Lazar Otasevic": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.6"
    "social_media_url": "",
    "platforms": {
        "watchos": "2.0",
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0"
    "source_files": [
    "public_header_files": "NSObject+RHBCasting.h"

Pin It on Pinterest

Share This