3

所以,我经常使用 NSArrays,所以我决定尝试创建一个宏,该宏将根据此处的宏从传入的原语创建一个数组:

https://bitbucket.org/snej/myutilities/src/319441e240fa/CollectionUtils.h

#define $array(values...) ({ void *v[] = { values }; const char *encodings[] = { /* how do I get the @encode-ings for each? */ };  _boxArray(v, encodings, sizeof(values) / sizeof(void *))})

NSValue *_box(void *value, const char *encoding); // defined by CollectionUtils

NSArray *_boxArray(void **values, const char **encodings, int count)
{
    id objects[count];

    for (int i = 0; i < count; i++) {
        // how can I box all of the values that need boxing?
        objects[i] = _box(values[i], encodings[i]);
    }

    return [NSArray arrayWithObjects:objects count:count];
}

所以基本上,我要问的是,如何使用可变参数宏对传递给宏的每个参数执行操作?

4

1 回答 1

1

这不是您问题的直接答案,但是...也许您应该等待 LLVM 4.0,其中包括原语的自动装箱功能?

看看:http ://blog.ablepear.com/2012/02/something-wonderful-new-objective-c.html

于 2012-03-03T16:25:20.293 回答