Skip to content

Commit 66a90bb

Browse files
committed
Make both ARTMessageAnnotations and ARTMessageVersion sendable.
1 parent 211c51d commit 66a90bb

4 files changed

Lines changed: 63 additions & 33 deletions

File tree

Source/ARTMessageAnnotations.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
@implementation ARTMessageAnnotations
55

66
- (instancetype)init {
7+
return [self initWithSummary:nil];
8+
}
9+
10+
- (instancetype)initWithSummary:(nullable ARTJsonObject *)summary {
711
self = [super init];
812
if (self) {
9-
_summary = nil;
13+
_summary = summary;
1014
}
1115
return self;
1216
}
1317

1418
- (id)copyWithZone:(NSZone *)zone {
15-
ARTMessageAnnotations *annotations = [[[self class] allocWithZone:zone] init];
16-
annotations.summary = self.summary;
19+
ARTMessageAnnotations *annotations = [[[self class] allocWithZone:zone] initWithSummary:self.summary];
1720
return annotations;
1821
}
1922

@@ -24,9 +27,7 @@ - (void)writeToDictionary:(NSMutableDictionary<NSString *, id> *)dictionary {
2427
}
2528

2629
+ (instancetype)createFromDictionary:(NSDictionary<NSString *, id> *)jsonObject {
27-
ARTMessageAnnotations *annotations = [[ARTMessageAnnotations alloc] init];
28-
annotations.summary = [jsonObject objectForKey:@"summary"];
29-
return annotations;
30+
return [[ARTMessageAnnotations alloc] initWithSummary:[jsonObject objectForKey:@"summary"]];
3031
}
3132

3233
- (NSString *)description {

Source/ARTMessageVersion.m

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,31 @@
66
@implementation ARTMessageVersion
77

88
- (instancetype)init {
9+
return [self initWithSerial:nil timestamp:nil clientId:nil descriptionText:nil metadata:nil];
10+
}
11+
12+
- (instancetype)initWithSerial:(nullable NSString *)serial
13+
timestamp:(nullable NSDate *)timestamp
14+
clientId:(nullable NSString *)clientId
15+
descriptionText:(nullable NSString *)descriptionText
16+
metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata {
917
self = [super init];
1018
if (self) {
11-
_serial = nil;
12-
_timestamp = nil;
13-
_clientId = nil;
14-
_descriptionText = nil;
15-
_metadata = nil;
19+
_serial = serial;
20+
_timestamp = timestamp;
21+
_clientId = clientId;
22+
_descriptionText = descriptionText;
23+
_metadata = metadata;
1624
}
1725
return self;
1826
}
1927

2028
- (id)copyWithZone:(NSZone *)zone {
21-
ARTMessageVersion *version = [[[self class] allocWithZone:zone] init];
22-
version.serial = self.serial;
23-
version.timestamp = self.timestamp;
24-
version.clientId = self.clientId;
25-
version.descriptionText = self.descriptionText;
26-
version.metadata = self.metadata;
27-
return version;
29+
return [[self.class allocWithZone:zone] initWithSerial:self.serial
30+
timestamp:self.timestamp
31+
clientId:self.clientId
32+
descriptionText:self.descriptionText
33+
metadata:self.metadata];
2834
}
2935

3036
- (void)writeToDictionary:(NSMutableDictionary<NSString *, id> *)dictionary {
@@ -46,18 +52,17 @@ - (void)writeToDictionary:(NSMutableDictionary<NSString *, id> *)dictionary {
4652
}
4753

4854
+ (instancetype)createFromDictionary:(NSDictionary<NSString *, id> *)jsonObject {
49-
ARTMessageVersion *version = [[ARTMessageVersion alloc] init];
50-
version.serial = [jsonObject artString:@"serial"];
51-
version.timestamp = [jsonObject artTimestamp:@"timestamp"];
52-
version.clientId = [jsonObject artString:@"clientId"];
53-
version.descriptionText = [jsonObject artString:@"description"];
54-
5555
id metadata = jsonObject[@"metadata"];
56+
NSDictionary<NSString *, NSString *> *metadataDict = nil;
5657
if (metadata && [metadata isKindOfClass:[NSDictionary class]]) {
57-
version.metadata = metadata;
58+
metadataDict = metadata;
5859
}
59-
60-
return version;
60+
61+
return [[ARTMessageVersion alloc] initWithSerial:[jsonObject artString:@"serial"]
62+
timestamp:[jsonObject artTimestamp:@"timestamp"]
63+
clientId:[jsonObject artString:@"clientId"]
64+
descriptionText:[jsonObject artString:@"description"]
65+
metadata:metadataDict];
6166
}
6267

6368
- (NSString *)description {

Source/include/Ably/ARTMessageAnnotations.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ NS_ASSUME_NONNULL_BEGIN
66
/**
77
* Contains annotations summary for a message. The keys of the dict are annotation types, and the values are aggregated summaries for that annotation type.
88
*/
9+
NS_SWIFT_SENDABLE
910
@interface ARTMessageAnnotations : NSObject
1011

1112
/// An annotations summary for the message. The keys of the dict are annotation types, and the values are aggregated summaries for that annotation type.
12-
@property (nonatomic, copy, nullable) ARTJsonObject *summary;
13+
@property (nonatomic, readonly, nullable) ARTJsonObject *summary;
14+
15+
/**
16+
* Initializes an `ARTMessageAnnotations` with all properties.
17+
*
18+
* @param summary An annotations summary for the message. The keys of the dict are annotation types, and the values are aggregated summaries for that annotation type.
19+
*/
20+
- (instancetype)initWithSummary:(nullable ARTJsonObject *)summary;
1321

1422
@end
1523

Source/include/Ably/ARTMessageVersion.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,38 @@ NS_ASSUME_NONNULL_BEGIN
66
/**
77
* Contains version information for a message, including operation metadata.
88
*/
9+
NS_SWIFT_SENDABLE
910
@interface ARTMessageVersion : NSObject
1011

1112
/// The serial of the message version.
12-
@property (nullable, readwrite, nonatomic) NSString *serial;
13+
@property (nullable, readonly, nonatomic) NSString *serial;
1314

1415
/// The timestamp of the message version.
15-
@property (nullable, readwrite, nonatomic) NSDate *timestamp;
16+
@property (nullable, readonly, nonatomic) NSDate *timestamp;
1617

1718
/// The client ID associated with this version.
18-
@property (nullable, readwrite, nonatomic) NSString *clientId;
19+
@property (nullable, readonly, nonatomic) NSString *clientId;
1920

2021
/// A description of the operation performed.
21-
@property (nullable, readwrite, nonatomic) NSString *descriptionText;
22+
@property (nullable, readonly, nonatomic) NSString *descriptionText;
2223

2324
/// Metadata associated with the operation.
24-
@property (nullable, readwrite, nonatomic) NSDictionary<NSString *, NSString *> *metadata;
25+
@property (nullable, readonly, nonatomic) NSDictionary<NSString *, NSString *> *metadata;
26+
27+
/**
28+
* Initializes an `ARTMessageVersion` with all properties.
29+
*
30+
* @param serial The serial of the message version.
31+
* @param timestamp The timestamp of the message version.
32+
* @param clientId The client ID associated with this version.
33+
* @param descriptionText A description of the operation performed.
34+
* @param metadata Metadata associated with the operation.
35+
*/
36+
- (instancetype)initWithSerial:(nullable NSString *)serial
37+
timestamp:(nullable NSDate *)timestamp
38+
clientId:(nullable NSString *)clientId
39+
descriptionText:(nullable NSString *)descriptionText
40+
metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata;
2541

2642
@end
2743

0 commit comments

Comments
 (0)