Skip to content

Commit

Permalink
Add NSCopying support to ART*ChannelOptions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lawrence-forooghian committed Jan 16, 2025
1 parent 113d452 commit 7410363
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Source/ARTChannelOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ - (instancetype)initWithCipherKey:(id<ARTCipherKeyCompatible>)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;
}
Expand Down
10 changes: 10 additions & 0 deletions Source/ARTRealtimeChannelOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ - (instancetype)initWithCipher:(id<ARTCipherParamsCompatible>)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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/include/Ably/ARTChannelOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Passes additional properties to an `ARTRestChannel` object, such as encryption.
*/
@interface ARTChannelOptions : NSObject
@interface ARTChannelOptions : NSObject <NSCopying>

/**
* 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).
Expand Down

0 comments on commit 7410363

Please sign in to comment.