NSMethodSignature を使用すると、getArgumentTypeAtIndex: を介してメソッドの引数の型を取得できます。このドキュメントに基づいて c-string を返します。int の場合は "i"、unsigned の場合は "I" のようになります。
このエンコーディングを受け取り、型のサイズをバイト単位で返す関数はどこかにありますか?
このようなもの:
int paramSize = typeEncodingSize("i");
NSLog(@"%s is %d bytes", "i", paramSize);
//this would be the encoding for a struct that has three fields. An id, a pointer and an int.
paramSize = typeEncodingSize("{example=@*i}"); //two 8 byte pointers & one 4 byte int
NSLog(@"%s is %d bytes", "{example=@*i}", paramSize);
which would output:
i is 4 bytes
{example=@*i} is 20 bytes
[NSInvocation setArgument:atIndex:]のドキュメントには、
コピーされるバイト数は、引数のサイズによって決まります。