FROM : Tommy Nordgren
DATE : Mon Jul 31 21:31:20 2006
Jul 31, 2006 kl. 8:49 PM skrev Bill Bumgarner:
>
> On Jul 31, 2006, at 11:23 AM, Tommy Nordgren wrote:
>
>> Can someone who have been using cocoa long please tell me how to
>> do this?
>> The signature should be like this:
>> -(BOOL) aMethod: (id) owner;
>
> What, exactly, are you trying to do?
>
This, to be extended with further methods:
@implementation NSCoder (ConditionalCoding)
-(void) encodeObject:(id) obj onCondition:(SEL) cond withOwner: (id)
owner
{
BOOL strongCode = NO;
NSMethodSignature * sign = [obj methodSignatureForSelector:cond];
if (sign == nil) {
strongCode = YES;
} else {
if ([sign numberOfArguments] == 3 &&
strcmp([sign getArgumentTypeAtIndex:2],@encode(id)) == 0 &&
strcmp([sign methodReturnType] , @encode(BOOL)) == 0) {
int i = (int) objc_msgSend(obj,cond,owner);
strongCode = i ? YES: NO;
}
}
if ( strongCode) {
[self encodeObject: obj];
} else {
[self encodeConditionalObject:obj];
}
}
@end
I welcome any comment on the code
> The Obj-C runtime supports introspection and you can grab the
> method signature and then rip it apart to deduce parameter and
> return types. To a degree; you lose with complex C types and
> certain other parameter types.
>
> I would suggest poking through the source code for one of the
> various Obj-C bridges to see the full details; PyObjC, F-Script
> (Smalltalk-esque), RubyCocoa, and CamelBones (Perl-ObjC) all
> introspect to do cross language method dispatches.
>
> b.bum
>
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.<email_removed>
DATE : Mon Jul 31 21:31:20 2006
Jul 31, 2006 kl. 8:49 PM skrev Bill Bumgarner:
>
> On Jul 31, 2006, at 11:23 AM, Tommy Nordgren wrote:
>
>> Can someone who have been using cocoa long please tell me how to
>> do this?
>> The signature should be like this:
>> -(BOOL) aMethod: (id) owner;
>
> What, exactly, are you trying to do?
>
This, to be extended with further methods:
@implementation NSCoder (ConditionalCoding)
-(void) encodeObject:(id) obj onCondition:(SEL) cond withOwner: (id)
owner
{
BOOL strongCode = NO;
NSMethodSignature * sign = [obj methodSignatureForSelector:cond];
if (sign == nil) {
strongCode = YES;
} else {
if ([sign numberOfArguments] == 3 &&
strcmp([sign getArgumentTypeAtIndex:2],@encode(id)) == 0 &&
strcmp([sign methodReturnType] , @encode(BOOL)) == 0) {
int i = (int) objc_msgSend(obj,cond,owner);
strongCode = i ? YES: NO;
}
}
if ( strongCode) {
[self encodeObject: obj];
} else {
[self encodeConditionalObject:obj];
}
}
@end
I welcome any comment on the code
> The Obj-C runtime supports introspection and you can grab the
> method signature and then rip it apart to deduce parameter and
> return types. To a degree; you lose with complex C types and
> certain other parameter types.
>
> I would suggest poking through the source code for one of the
> various Obj-C bridges to see the full details; PyObjC, F-Script
> (Smalltalk-esque), RubyCocoa, and CamelBones (Perl-ObjC) all
> introspect to do cross language method dispatches.
>
> b.bum
>
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.<email_removed>
| Related mails | Author | Date |
|---|---|---|
| Tommy Nordgren | Jul 31, 20:23 | |
| Andrei Tchijov | Jul 31, 20:30 | |
| Ryan Britton | Jul 31, 20:32 | |
| Sherm Pendley | Jul 31, 20:39 | |
| Bill Bumgarner | Jul 31, 20:49 | |
| Tommy Nordgren | Jul 31, 21:31 | |
| Erik Buck | Jul 31, 23:19 | |
| Michael Ash | Aug 1, 01:09 |






Cocoa mail archive

