Skip to content

Commit

Permalink
Remove nullability of -subscribe* return value
Browse files Browse the repository at this point in the history
There’s no reason for these to be nullable (it just makes it harder to
call the -unsubscribe methods, which take a nonnull listener), and the
return type of the underlying methods is nonnull.
  • Loading branch information
lawrence-forooghian committed Jan 13, 2025
1 parent 23485fa commit e07f44c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ - (void)detach:(nullable ARTCallback)callback {
[_internal detach:callback];
}

- (ARTEventListener *_Nullable)subscribe:(ARTMessageCallback)callback {
- (ARTEventListener *)subscribe:(ARTMessageCallback)callback {
return [_internal subscribe:callback];
}

- (ARTEventListener *_Nullable)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)cb {
- (ARTEventListener *)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)cb {
return [_internal subscribeWithAttachCallback:onAttach callback:cb];
}

- (ARTEventListener *_Nullable)subscribe:(NSString *)name callback:(ARTMessageCallback)cb {
- (ARTEventListener *)subscribe:(NSString *)name callback:(ARTMessageCallback)cb {
return [_internal subscribe:name callback:cb];
}

- (ARTEventListener *_Nullable)subscribe:(NSString *)name onAttach:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)cb {
- (ARTEventListener *)subscribe:(NSString *)name onAttach:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)cb {
return [_internal subscribe:name onAttach:onAttach callback:cb];
}

Expand Down
8 changes: 4 additions & 4 deletions Source/ARTRealtimePresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ - (void)leaveClient:(NSString *)clientId data:(id _Nullable)data callback:(nulla
[_internal leaveClient:clientId data:data callback:cb];
}

- (ARTEventListener *_Nullable)subscribe:(ARTPresenceMessageCallback)callback {
- (ARTEventListener *)subscribe:(ARTPresenceMessageCallback)callback {
return [_internal subscribe:callback];
}

- (ARTEventListener *_Nullable)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)cb {
- (ARTEventListener *)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)cb {
return [_internal subscribeWithAttachCallback:onAttach callback:cb];
}

- (ARTEventListener *_Nullable)subscribe:(ARTPresenceAction)action callback:(ARTPresenceMessageCallback)cb {
- (ARTEventListener *)subscribe:(ARTPresenceAction)action callback:(ARTPresenceMessageCallback)cb {
return [_internal subscribe:action callback:cb];
}

- (ARTEventListener *_Nullable)subscribe:(ARTPresenceAction)action onAttach:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)cb {
- (ARTEventListener *)subscribe:(ARTPresenceAction)action onAttach:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)cb {
return [_internal subscribe:action onAttach:onAttach callback:cb];
}

Expand Down
8 changes: 4 additions & 4 deletions Source/include/Ably/ARTRealtimeChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @see See `subscribeWithAttachCallback:` for more details.
*/
- (ARTEventListener *_Nullable)subscribe:(ARTMessageCallback)callback;
- (ARTEventListener *)subscribe:(ARTMessageCallback)callback;

/**
* Registers a listener for messages on this channel. The caller supplies a listener function, which is called each time one or more messages arrives on the channel.
Expand All @@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An `ARTEventListener` object.
*/
- (ARTEventListener *_Nullable)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)callback;
- (ARTEventListener *)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)callback;

/**
* Registers a listener for messages with a given event `name` on this channel. The caller supplies a listener function, which is called each time one or more matching messages arrives on the channel.
Expand All @@ -99,7 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @see See `subscribeWithAttachCallback:` for more details.
*/
- (ARTEventListener *_Nullable)subscribe:(NSString *)name callback:(ARTMessageCallback)callback;
- (ARTEventListener *)subscribe:(NSString *)name callback:(ARTMessageCallback)callback;

/**
* Registers a listener for messages with a given event `name` on this channel. The caller supplies a listener function, which is called each time one or more matching messages arrives on the channel. A callback may optionally be passed in to this call to be notified of success or failure of the channel `-[ARTRealtimeChannelProtocol attach]` operation. It will not be called if the `ARTRealtimeChannelOptions.attachOnSubscribe` channel option is set to `false`.
Expand All @@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An `ARTEventListener` object.
*/
- (ARTEventListener *_Nullable)subscribe:(NSString *)name onAttach:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)callback;
- (ARTEventListener *)subscribe:(NSString *)name onAttach:(nullable ARTCallback)onAttach callback:(ARTMessageCallback)callback;

/**
* Deregisters all listeners to messages on this channel. This removes all earlier subscriptions.
Expand Down
8 changes: 4 additions & 4 deletions Source/include/Ably/ARTRealtimePresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An event listener object.
*/
- (ARTEventListener *_Nullable)subscribe:(ARTPresenceMessageCallback)callback;
- (ARTEventListener *)subscribe:(ARTPresenceMessageCallback)callback;

/**
* Registers a listener that is called each time a `ARTPresenceMessage` is received on the channel, such as a new member entering the presence set. A callback may optionally be passed in to this call to be notified of success or failure of the channel `-[ARTRealtimeChannelProtocol attach]` operation. It will not be called if the `ARTRealtimeChannelOptions.attachOnSubscribe` channel option is set to `false`.
Expand All @@ -152,7 +152,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An event listener object.
*/
- (ARTEventListener *_Nullable)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)callback;
- (ARTEventListener *)subscribeWithAttachCallback:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)callback;

/**
* Registers a listener that is called each time a `ARTPresenceMessage` matching a given `ARTPresenceAction` is received on the channel, such as a new member entering the presence set.
Expand All @@ -162,7 +162,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An event listener object.
*/
- (ARTEventListener *_Nullable)subscribe:(ARTPresenceAction)action callback:(ARTPresenceMessageCallback)callback;
- (ARTEventListener *)subscribe:(ARTPresenceAction)action callback:(ARTPresenceMessageCallback)callback;

/**
* Registers a listener that is called each time a `ARTPresenceMessage` matching a given `ARTPresenceAction` is received on the channel, such as a new member entering the presence set. A callback may optionally be passed in to this call to be notified of success or failure of the channel `-[ARTRealtimeChannelProtocol attach]` operation. It will not be called if the `ARTRealtimeChannelOptions.attachOnSubscribe` channel option is set to `false`.
Expand All @@ -173,7 +173,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An event listener object.
*/
- (ARTEventListener *_Nullable)subscribe:(ARTPresenceAction)action onAttach:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)callback;
- (ARTEventListener *)subscribe:(ARTPresenceAction)action onAttach:(nullable ARTCallback)onAttach callback:(ARTPresenceMessageCallback)callback;

/**
* Deregisters all listeners currently receiving `ARTPresenceMessage` for the channel.
Expand Down
4 changes: 2 additions & 2 deletions Test/Tests/RealtimeClientPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class RealtimeClientPresenceTests: XCTestCase {
defer { client.dispose(); client.close() }
let channel = client.channels.get(test.uniqueChannelName())

let listener = channel.presence.subscribe { _ in }!
let listener = channel.presence.subscribe { _ in }
XCTAssertEqual(channel.internal.internalPresence.eventEmitter.anyListeners.count, 1)
channel.presence.unsubscribe(listener)
XCTAssertEqual(channel.internal.internalPresence.eventEmitter.anyListeners.count, 0)
Expand Down Expand Up @@ -878,7 +878,7 @@ class RealtimeClientPresenceTests: XCTestCase {
defer { client.dispose(); client.close() }
let channel = client.channels.get(test.uniqueChannelName())

let listener = channel.presence.subscribe(.present) { _ in }!
let listener = channel.presence.subscribe(.present) { _ in }
XCTAssertEqual(channel.internal.internalPresence.eventEmitter.listeners.count, 1)
channel.presence.unsubscribe(.present, listener: listener)
XCTAssertEqual(channel.internal.internalPresence.eventEmitter.listeners.count, 0)
Expand Down

0 comments on commit e07f44c

Please sign in to comment.