所以,我用NSArrays了很多,所以我決定嘗試創建,將創建傳遞原語的數組宏的基礎上,宏這裏:自動裝箱NSArray?
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];
}
所以基本上,我問的是,如何通過可變宏來對每個傳遞給宏的參數執行操作?
什麼都沒有,呃? – 2012-03-03 00:17:22