On Oct 2, 2010, at 11:51 PM, Gordon Apple wrote:
> I assume that object ids get assigned at run time.
An object "id" is just its plain memory address. When an object is created and its memory get allocated, it gets "id".
(A few objects might get addresses/ids alloc'd link time -- e.g., string constants -- but that's just a side note.)
> What about selectors?
They are (at this moment, it might change in future, though such a change is very improbable) also addresses -- addresses of message-descripting structures in ObjC runtime tables.
These tables are created compile-time, and the concrete addresses get fixed link-time.
For your purpose though selectors are of no use, for their values are process-specific: you can depend on a message to always get the same selector inside a process, but the very same message might get a different selector in another process.
Use plain message names (see NSStringFromSelector).
> I'm looking at doing remote control, say between two iPads or between an
> iPhone and an iPad, or either one to a Mac application.
If you happen to be focused on iOS-iOS and Mac is not that important, read on GameKit. It is a very improperly named general bluetooth-based communication library, nothing game-specific there; and it is quite easy to use.
Alas, betwixt iOS and Mac OS X you must go TCP (since far as I know -- someone please correct me if I am wrong -- there's no GameKit for Mac OS X and hardly there will ever be, for the protocol is undocumented; and there is no way to control bluetooth low-level on iOS).
> I was wondering if there is a way to simply send normal code messages
> instead, using a uniform message translator.
There is a much better way, check Distributed Objects (NSConnection etc.) Alas, for reasons unknown, unsupported on iOS, so it's not a big help for you; nevertheless, it's a good example of what you can rig for yourself.
> Would this require exposing a
> table of selectors and ids which the remote control unit would read when
> first connecting? Is this practical? Is there anything obvious I'm missing
Actually for a RC I would guess a hi-level control protocol based on text commands which not necessarily are represented by ObjC messages on either side might be a better solution.
Nevertheless, if you want to do that, it's not that difficult. You need to transfer class names, message names, and object addresses (ids); the last need to be translated to local proxy objects (see NSProxy) and uniqued. See the aforementioned DO's for details of a concrete (and very good) implementation; you can play with them on Mac OS X to see how it works.
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden