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 }
  • 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.

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.