「NSInvocationをカテゴリで拡張した」の修正¶
以前の、「NSInvocationをカテゴリで拡張した」の修正。
詳解Objective-C 2.0 第三版 P537より、KVCで自動変換出来る構造体は、
自動的に受け渡し出来るのはCocoaで標準的に使われている四種類の構造体 NSPoint, NSRange, NSRect, NSSizeに限られています。
との事なので、NSPoint, NSRange, NSRect, NSSizeの四つの構造体をサポートするように変更する。
if文の固まりの末尾に、以下を追加した。
else if( 0 == strcmp(theReturnType, @encode(NSPoint)) )
{
theResult = [NSValue valueWithPoint:*(NSPoint*)thePtr];
}
else if( 0 == strcmp(theReturnType, @encode(NSSize)) )
{
theResult = [NSValue valueWithSize:*(NSSize*)thePtr];
}
else if( 0 == strcmp(theReturnType, @encode(NSRect)) )
{
theResult = [NSValue valueWithRect:*(NSRect*)thePtr];
}
else if( 0 == strcmp(theReturnType, @encode(NSRange)) )
{
theResult = [NSValue valueWithRange:*(NSRange*)thePtr];
}
else
{
theResult = [NSValue valueWithBytes:thePtr
objCType:theReturnType];
}
以上のサポートでKVCで標準でサポートしている型の自動変換をサポートしたハズ。
Comments
comments powered by Disqus