|
|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
#include <objc/blocks_runtime.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
struct big
|
|
|
|
|
{
|
|
|
|
|
@ -23,7 +24,10 @@ int main(void)
|
|
|
|
|
return b; };
|
|
|
|
|
blk = Block_copy(blk);
|
|
|
|
|
IMP imp = imp_implementationWithBlock(blk);
|
|
|
|
|
class_addMethod((objc_getMetaClass("Foo")), @selector(count:), imp, "i@:i");
|
|
|
|
|
char *type = block_copyIMPTypeEncoding_np(blk);
|
|
|
|
|
assert(NULL != type);
|
|
|
|
|
class_addMethod((objc_getMetaClass("Foo")), @selector(count:), imp, type);
|
|
|
|
|
free(type);
|
|
|
|
|
assert(2 == [Foo count: 2]);
|
|
|
|
|
assert(4 == [Foo count: 2]);
|
|
|
|
|
assert(6 == [Foo count: 2]);
|
|
|
|
|
@ -36,9 +40,10 @@ int main(void)
|
|
|
|
|
};
|
|
|
|
|
imp = imp_implementationWithBlock(blk);
|
|
|
|
|
assert(imp && "Can't make sret IMP");
|
|
|
|
|
char *type;
|
|
|
|
|
asprintf(&type, "%s@:", @encode(struct big));
|
|
|
|
|
type = block_copyIMPTypeEncoding_np(blk);
|
|
|
|
|
assert(NULL != type);
|
|
|
|
|
class_addMethod((objc_getMetaClass("Foo")), @selector(sret), imp, type);
|
|
|
|
|
free(type);
|
|
|
|
|
struct big s = [Foo sret];
|
|
|
|
|
assert(s.a == 1);
|
|
|
|
|
assert(s.b == 2);
|
|
|
|
|
|