GithubHelp home page GithubHelp logo

kimbin / ctobjectivecruntimeadditions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ebf/ctobjectivecruntimeadditions

0.0 1.0 0.0 233 KB

Objc runtime additions.

License: MIT License

Objective-C 100.00%

ctobjectivecruntimeadditions's Introduction

CTObjectiveCRuntimeAdditions

CTObjectiveCRuntimeAdditions introduces the following new runtime additions:

  • void class_swizzleSelector(Class class, SEL originalSelector, SEL newSelector);
  • void class_swizzlesMethodsWithPrefix(Class class, NSString *prefix);
  • void class_enumerateMethodList(Class class, CTMethodEnumertor enumerator);
  • Class class_subclassPassingTest(Class class, CTClassTest test);
  • IMP class_replaceMethodWithBlock(Class class, SEL originalSelector, id block);
  • void class_implementPropertyInUserDefaults(Class class, NSString *propertyName, BOOL automaticSynchronizeUserDefaults);
  • void class_implementProperty(Class class, NSString *propertyName, objc_AssociationPolicy associationPolicy);

Getting runtime information about blocks

CTBlockDescription lets you inspect blocks including arguments and compile time features at runtime.

One could use CTBlockDescription for the following test block:

// a test block.
BOOL(^testBlock)(BOOL animated, id object) = ^BOOL(BOOL animated, id object) {
    return YES;
};

// allocating a block description
CTBlockDescription *blockDescription = [[CTBlockDescription alloc] initWithBlock:testBlock];

// getting a method signature for this block
NSMethodSignature *methodSignature = blockDescription.blockSignature;
/**
<NSMethodSignature: 0x253f080>
    number of arguments = 3
    frame size = 12
    is special struct return? NO
    return value: -------- -------- -------- --------
        type encoding (c) 'c'
        flags {isSigned}
        modifiers {}
        frame {offset = 0, offset adjust = 0, size = 4, size adjust = -3}
        memory {offset = 0, size = 1}
    argument 0: -------- -------- -------- --------
        type encoding (@) '@?'
        flags {isObject, isBlock}
        modifiers {}
        frame {offset = 0, offset adjust = 0, size = 4, size adjust = 0}
        memory {offset = 0, size = 4}
    argument 1: -------- -------- -------- --------
        type encoding (c) 'c'
        flags {isSigned}
        modifiers {}
        frame {offset = 4, offset adjust = 0, size = 4, size adjust = -3}
        memory {offset = 0, size = 1}
    argument 2: -------- -------- -------- --------
        type encoding (@) '@'
        flags {isObject}
        modifiers {}
        frame {offset = 8, offset adjust = 0, size = 4, size adjust = 0}
        memory {offset = 0, size = 4}
*/

License

MIT

Thanks goes to the Block Implementation Specification and the A2DynamicDelegate project for some good libffi samples and convertion from encodings to libffi types.

ctobjectivecruntimeadditions's People

Contributors

oliverletterer avatar rabovik avatar

Watchers

kimbin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.