From 74103637ccf1a3e799d4b1018baca4d292204b36 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 15 Jan 2025 17:27:48 -0300 Subject: [PATCH] Add NSCopying support to ART*ChannelOptions Will use in an upcoming commit, but it's also handy for users of the SDK (e.g. I had already found myself wanting it in Chat, when wishing to create a modified version of an options object recevied as an argument). TODO test --- Source/ARTChannelOptions.m | 11 +++++++++++ Source/ARTRealtimeChannelOptions.m | 10 ++++++++++ Source/include/Ably/ARTChannelOptions.h | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/ARTChannelOptions.m b/Source/ARTChannelOptions.m index 5da50e890..aa60a1de3 100644 --- a/Source/ARTChannelOptions.m +++ b/Source/ARTChannelOptions.m @@ -17,6 +17,17 @@ - (instancetype)initWithCipherKey:(id)key { return [self initWithCipher:@{@"key": key}]; } +- (id)copyWithZone:(NSZone *)zone { + ARTChannelOptions *copied = [[[self class] alloc] init]; + + // The _frozen flag prevents the instance we were copying from being mutated, but we don't yet want to prevent the new instance from being mutated + copied->_frozen = NO; + + copied->_cipher = _cipher; + + return self; +} + - (ARTCipherParams *)cipher { return _cipher; } diff --git a/Source/ARTRealtimeChannelOptions.m b/Source/ARTRealtimeChannelOptions.m index ad08ed8fa..7df7bdaef 100644 --- a/Source/ARTRealtimeChannelOptions.m +++ b/Source/ARTRealtimeChannelOptions.m @@ -21,6 +21,16 @@ - (instancetype)initWithCipher:(id)cipherParams { return self; } +- (id)copyWithZone:(NSZone *)zone { + ARTRealtimeChannelOptions *copied = [super copy]; + + copied->_params = _params; + copied->_modes = _modes; + copied->_attachOnSubscribe = _attachOnSubscribe; + + return copied; +} + - (NSStringDictionary *)params { return _params; } diff --git a/Source/include/Ably/ARTChannelOptions.h b/Source/include/Ably/ARTChannelOptions.h index f7028d517..042b19346 100644 --- a/Source/include/Ably/ARTChannelOptions.h +++ b/Source/include/Ably/ARTChannelOptions.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Passes additional properties to an `ARTRestChannel` object, such as encryption. */ -@interface ARTChannelOptions : NSObject +@interface ARTChannelOptions : NSObject /** * Requests encryption for this channel when not `nil`, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key). See [an example](https://ably.com/docs/realtime/encryption#getting-started).