ARTMessage

Objective-C

@interface ARTMessage : ARTBaseMessage

Swift

class ARTMessage : ARTBaseMessage

Contains an individual message that is sent to, or received from, Ably.

  • The event name, if available

    Declaration

    Objective-C

    @property (nonatomic, nullable) NSString *name;

    Swift

    var name: String? { get set }
  • The action type of the message, one of the ARTMessageAction enum values.

    Note

    A message that you create via the initWithName:data: or initWithName:data:clientId: initializers will have an action of ARTMessageActionCreate. However, the value of this property will be ignored when you pass this message to the SDK (e.g. when publishing the message).

    Declaration

    Objective-C

    @property (nonatomic) ARTMessageAction action;

    Swift

    var action: ARTMessageAction { get set }
  • This message’s unique serial (an identifier that will be the same in all future updates of this message).

    Declaration

    Objective-C

    @property (nonatomic, nullable) NSString *serial;

    Swift

    var serial: String? { get set }
  • The version information for the message, containing serial, timestamp, and operation metadata.

    Declaration

    Objective-C

    @property (nonatomic, nullable) ARTMessageVersion *version;

    Swift

    var version: ARTMessageVersion? { get set }
  • Contains annotations for the message, including summary data.

    Declaration

    Objective-C

    @property (nonatomic, nullable) ARTMessageAnnotations *annotations;

    Swift

    var annotations: ARTMessageAnnotations? { get set }
  • Construct an ARTMessage object with an event name and payload.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithName:(nullable NSString *)name
                                    data:(nonnull id)data;

    Swift

    init(name: String?, data: Any)

    Parameters

    name

    The event name.

    data

    The message payload.

  • Construct an ARTMessage object with an event name, payload, and a unique client ID.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithName:(nullable NSString *)name
                                    data:(nonnull id)data
                                clientId:(nonnull NSString *)clientId;

    Swift

    init(name: String?, data: Any, clientId: String)

    Parameters

    name

    The event name.

    data

    The message payload.

    clientId

    The client ID of the publisher of this message.

  • Whether the action property has been set by the internals of the SDK.

    This property defaults to NO, indicating that the action property is either the default value or has been set by the user. As described in the documentation for action, this means that the SDK should ignore the value of this property. In particular, it should not populate this property when sending this message over the wire.

    Note

    If we had a separate WireMessage type instead of using ARTMessage as both our internal and external representation of a message, then we wouldn’t need this mechanism. But we don’t.

    Declaration

    Objective-C

    @property (nonatomic) BOOL actionIsInternallySet;

    Swift

    var actionIsInternallySet: Bool { get set }

Decoding

  • A static factory method to create an ARTMessage object from a deserialized Message-like object encoded using Ably’s wire protocol.

    Declaration

    Objective-C

    + (nullable instancetype)fromEncoded:(nonnull NSDictionary *)jsonObject
                          channelOptions:(nonnull ARTChannelOptions *)options
                                   error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func fromEncoded(_ jsonObject: [AnyHashable : Any], channelOptions options: ARTChannelOptions) throws -> Self

    Parameters

    jsonObject

    A Message-like deserialized object.

    options

    An ARTChannelOptions object. If you have an encrypted channel, use this to allow the library to decrypt the data.

    Return Value

    An ARTMessage object.

  • A static factory method to create an array of ARTMessage objects from an array of deserialized Message-like object encoded using Ably’s wire protocol.

    Declaration

    Objective-C

    + (nullable NSArray<ARTMessage *> *)
        fromEncodedArray:(nonnull NSArray<NSDictionary *> *)jsonArray
          channelOptions:(nonnull ARTChannelOptions *)options
                   error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func fromEncodedArray(_ jsonArray: [[AnyHashable : Any]], channelOptions options: ARTChannelOptions) throws -> [ARTMessage]

    Parameters

    jsonArray

    An array of Message-like deserialized objects.

    options

    An ARTChannelOptions object. If you have an encrypted channel, use this to allow the library to decrypt the data.

    Return Value

    An array of ARTMessage objects.