Remote Messaging

Objective-C’s method call model lends itself well to distributed systems, where sending messages is the fundamental unit of interaction. The key difference in distributed systems is that objects may exist in different address spaces, and so cannot call each other directly.

Objects that want to receive messages from other processes must specify those messages in a formal protocol. Objective-C provides special keywords to use when writing such a formal protocol that qualify the kind of sharing you will need for that protocol’s message parameters.

You use the keywords to modify (or qualify) the type of a method’s parameter or return value. For example, the keywords out and in modify the parameters in the following declaration:

-(void)getData:(out 
            Data*)data 
            forIndex:(in 
            int)index;

The signature of this method says that index is only passed in and changes to it don’t need to be returned, but the method will modify the value of data.

You can’t use these keywords in class or category declarations. However, if your class or category adopts a protocol that uses a remote messaging keyword, you can repeat the keyword in the method signature of the implementation.

The remote messaging keywords can be grouped into three categories: those for pointer parameters, those for return values, and those for object qualifiers.

Pointer Parameter Qualifiers

This section discusses qualifiers that generally apply to pointer arguments. They tell the compiler how to handle copying values between ...

Get Objective-C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.