Ask a Question related to Mac Programming, Design and Development.
-
Andrew Hunter #1
Re: Can one pass variables through a selector?
In article <clund-50F2A4.12443709092003@amstwist00.chello.com>, C Lund wrote:
Yes - either use an NSInvocation to perform the call, or call objc_msgSend()> Assuming the following declarations:
>
> SEL selectorName;
>
> -(void)aCoordi:(int)iCoord j:(int)jCoord;
> -(void)bCoordi:(int)iCoord j:(int)jCoord;
> -(void)cCoordi:(int)iCoord j:(int)jCoord;
>
> And the above are called by:
>
> [self performSelector:selectorName];
>
> Is there any way to pass iCoord and jCoord through the selector or
> would I have to make iCoord and jCoord global (within the class)? I
> suspect the latter, but I'm asking just in case it can be done.
directly. NSInvocation is the 'official' way to do it, and is mentioned
in the docs for performSelector:.
Andrew.
Andrew Hunter Guest
-
CF pass variables to Flash
Hello: Basically I want Coldfusion to pass the server date to Flash. But I get '#theDt#' instead of the value of 'theDt' please see the code... -
Interesting Pass Variables to Flash
What I am attempting to do in a whole is to create swf files that will be drawn from several premaid swf's, alls I want to do is change the data... -
Postfields in WML does not pass all variables to next WML page
I am writing a function as listed below. My problem is that this form passes only the variable 'state' and not the others. Can somebody help me? ... -
pass variables when execute a Dir movie
Hello, I'd like to know if it's possible to initialize a Director movie from othe application (for example C++Builder) passing it already some... -
IS it better to use session variables or pass a URL variable
Yes, I am sure the answer starts with - It depends... Well, I am trying to get a person's name from one page to the next. The name will obviously... -
Doc O'Leary #2
Re: Can one pass variables through a selector?
In article <clund-50F2A4.12443709092003@amstwist00.chello.com>,
C Lund <clund@NOSPAMnotam02.no> wrote:
Look at NSInvocation instead.> Is there any way to pass iCoord and jCoord through the selector or
> would I have to make iCoord and jCoord global (within the class)? I
> suspect the latter, but I'm asking just in case it can be done.
Doc O'Leary Guest
-
Michael Milvich #3
Re: Can one pass variables through a selector?
C Lund <clund@NOSPAMnotam02.no> wrote in message news:<clund-50F2A4.12443709092003@amstwist00.chello.com>...
Take a look at NSInvocation. Basicly you need to follow these steps:> Assuming the following declarations:
>
> SEL selectorName;
>
> -(void)aCoordi:(int)iCoord j:(int)jCoord;
> -(void)bCoordi:(int)iCoord j:(int)jCoord;
> -(void)cCoordi:(int)iCoord j:(int)jCoord;
>
> And the above are called by:
>
> [self performSelector:selectorName];
>
> Is there any way to pass iCoord and jCoord through the selector or
> would I have to make iCoord and jCoord global (within the class)? I
> suspect the latter, but I'm asking just in case it can be done.
1) Convert your SEL into NSMethodSignature using -methodSignatureForSelector:
2) Create an NSInvocation object using that method signature
3) Set the arguments in the invocation object using -setArgument:atIndex:
4) Send invokeWithTarget: to the invocation object
Michael
Michael Milvich Guest
-
Michael Ash #4
Re: Can one pass variables through a selector?
In article <clund-50F2A4.12443709092003@amstwist00.chello.com>,
C Lund <clund@NOSPAMnotam02.no> wrote:
You can just do [object performSelector:@selector(aCoordi:j:)> Assuming the following declarations:
>
> SEL selectorName;
>
> -(void)aCoordi:(int)iCoord j:(int)jCoord;
> -(void)bCoordi:(int)iCoord j:(int)jCoord;
> -(void)cCoordi:(int)iCoord j:(int)jCoord;
>
> And the above are called by:
>
> [self performSelector:selectorName];
>
> Is there any way to pass iCoord and jCoord through the selector or
> would I have to make iCoord and jCoord global (within the class)? I
> suspect the latter, but I'm asking just in case it can be done.
withObject:iCoord withObject:jCoord]. This is a hack, because you're
relying on the fact that you can treat integers as objects if you don't
send messages to them, in current incarnations of Mac OS X. This will
break if you compile for a hypothetical 64-bit version of OS X which
would have 64-bit pointers. PerfomSelector:withObject:withObject:
doesn't send messages, it just passes them along, but that's also
somewhat dangerous to rely on.
Otherwise, you can simply do objc_msgSend(object, @selector(aCoordi:j:),
iCoord, jCoord). Whevere you send a message with [] it gets pretty much
directly translated to a call to objc_msgSend() anyway.
IMO using NSInvocation for this is overkill.
Michael Ash Guest
-
C Lund #5
Re: Can one pass variables through a selector?
In article <mail-6B537B.23515709092003@localhost>,
Michael Ash <mail@mikeash.com> wrote:
Wouldn't a recompile for a 64-bit OS fix it again?> You can just do [object performSelector:@selector(aCoordi:j:)
> withObject:iCoord withObject:jCoord]. This is a hack, because you're
> relying on the fact that you can treat integers as objects if you don't
> send messages to them, in current incarnations of Mac OS X. This will
> break if you compile for a hypothetical 64-bit version of OS X which
> would have 64-bit pointers.
BTW: Thanks for all the answers to my question. B)
--
C Lund, [url]www.notam02.no/~clund[/url]
C Lund Guest
-
Michael Milvich #6
Re: Can one pass variables through a selector?
C Lund <clund@NOSPAMnotam02.no> wrote in message news:<clund-017CFA.10003810092003@amstwist00.chello.com>...
No it wouldn't. Its a hack because a 32 bit pointer looks just like a> In article <mail-6B537B.23515709092003@localhost>,
> Michael Ash <mail@mikeash.com> wrote:
>>> > You can just do [object performSelector:@selector(aCoordi:j:)
> > withObject:iCoord withObject:jCoord]. This is a hack, because you're
> > relying on the fact that you can treat integers as objects if you don't
> > send messages to them, in current incarnations of Mac OS X. This will
> > break if you compile for a hypothetical 64-bit version of OS X which
> > would have 64-bit pointers.
> Wouldn't a recompile for a 64-bit OS fix it again?
32 bit integer. As long as you don't dereference the pointer everyone
is happy. When you recompile for 64-bit it will create a stack frame
with two 64 bit pointers or 128 bits worth of data, where your method
was only expecting two 32 bit ints or 64 bits of data. I suppose you
could change everything to longs and pass around 64 bit integers, but
that is weak.
Michael
Michael Milvich Guest



Reply With Quote

