SLObjectiveCRuntimeAdditions 1.2.2

SLObjectiveCRuntimeAdditions 1.2.2

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最新发布2015年10月

Oliver Letterer 管理。



  • Oliver Letterer

SLObjectiveCRuntimeAdditions 引入了以下新的运行时添加

  • void class_swizzleSelector(Class class, SEL originalSelector, SEL newSelector);
  • void class_swizzlesMethodsWithPrefix(Class class, NSString *prefix);
  • void class_enumerateMethodList(Class class, SLMethodEnumertor enumerator);
  • Class class_subclassPassingTest(Class class, SLClassTest 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);

获取关于 blocks 的运行时信息

SLBlockDescription 允许您在运行时检查 blocks,包括参数和编译时特征。

可以使用 SLBlockDescription 对以下测试 block 进行测试

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

// allocating a block description
SLBlockDescription *blockDescription = [[SLBlockDescription 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}
*/

许可

MIT

要感谢 Block 实现规范A2DynamicDelegate 项目,其中包含一些良好的 libffi 样本以及从编码转换为 libffi 类型的转换。