diff --git a/Pod/Classes/NSDictionary+QueryString.h b/Pod/Classes/NSDictionary+QueryString.h index 59c7a68..92c928c 100644 --- a/Pod/Classes/NSDictionary+QueryString.h +++ b/Pod/Classes/NSDictionary+QueryString.h @@ -8,7 +8,11 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface NSDictionary (QueryString) + (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString; - (NSString *)queryStringValue; @end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/NSDictionary+QueryString.m b/Pod/Classes/NSDictionary+QueryString.m index 28fe181..3a3dc20 100644 --- a/Pod/Classes/NSDictionary+QueryString.m +++ b/Pod/Classes/NSDictionary+QueryString.m @@ -11,8 +11,7 @@ @implementation NSDictionary (QueryString) -+ (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString -{ ++ (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSArray *pairs = [queryString componentsSeparatedByString:@"&"]; @@ -26,11 +25,13 @@ + (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString NSString *decodedKey = [key URLDecodedString]; NSString *decodedValue = [value URLDecodedString]; - if (![key isEqualToString:decodedKey]) + if (![key isEqualToString:decodedKey]) { key = decodedKey; + } - if (![value isEqualToString:decodedValue]) + if (![value isEqualToString:decodedValue]) { value = decodedValue; + } [dictionary setObject:value forKey:key]; } @@ -39,8 +40,7 @@ + (NSDictionary *)dictionaryWithQueryString:(NSString *)queryString return [NSDictionary dictionaryWithDictionary:dictionary]; } -- (NSString *)queryStringValue -{ +- (NSString *)queryStringValue { NSMutableArray *pairs = [NSMutableArray array]; for (NSString *key in [self keyEnumerator]) { diff --git a/Pod/Classes/NSString+URLEncoding.h b/Pod/Classes/NSString+URLEncoding.h index 96d4a7f..18435ab 100644 --- a/Pod/Classes/NSString+URLEncoding.h +++ b/Pod/Classes/NSString+URLEncoding.h @@ -8,7 +8,11 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface NSString (URLEncoding) - (NSString *)URLEncodedString; - (NSString *)URLDecodedString; @end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxChannel.h b/Pod/Classes/PhxChannel.h index fcf8dce..a0d6d91 100644 --- a/Pod/Classes/PhxChannel.h +++ b/Pod/Classes/PhxChannel.h @@ -9,6 +9,7 @@ #import #import "PhxTypes.h" +NS_ASSUME_NONNULL_BEGIN @class PhxSocket; @class PhxChannel; @@ -26,12 +27,12 @@ @property (nonatomic, weak) id delegate; @property (nonatomic, weak) PhxSocket* socket; @property (nonatomic, readonly) ChannelState state; -@property (nonatomic, retain) NSString* topic; -@property (nonatomic, retain) NSDictionary *params; +@property (nonatomic, strong) NSString* topic; +@property (nonatomic, strong) NSDictionary *params; -- (id)initWithSocket:(PhxSocket*)socket - topic:(NSString*)topic - params:(NSDictionary*)params; +- (instancetype)initWithSocket:(PhxSocket*)socket + topic:(NSString*)topic + params:(nullable NSDictionary*)params; - (PhxPush*)join; - (void)leave; @@ -44,4 +45,6 @@ - (PhxPush*)pushEvent:(NSString*)event payload:(NSDictionary*)payload; -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxChannel.m b/Pod/Classes/PhxChannel.m index 3a23158..43ad689 100644 --- a/Pod/Classes/PhxChannel.m +++ b/Pod/Classes/PhxChannel.m @@ -12,20 +12,24 @@ #import "PhxSocket.h" #import "PhxSocket_Private.h" +NS_ASSUME_NONNULL_BEGIN + @interface PhxChannel () -@property (nonatomic, readwrite) ChannelState state; +@property (nonatomic) ChannelState state; -@property (nonatomic, retain) NSMutableArray *bindings; +@property (nonatomic, strong) NSMutableArray *bindings; -@property (readwrite) BOOL joinedOnce; -@property (nonatomic, retain) PhxPush *joinPush; +@property (atomic) BOOL joinedOnce; +@property (nonatomic, strong) PhxPush *joinPush; @end @implementation PhxChannel -- (id)initWithSocket:(PhxSocket *)socket topic:(NSString *)topic params:(NSDictionary *)params { +- (instancetype)initWithSocket:(PhxSocket *)socket + topic:(NSString *)topic + params:(nullable NSDictionary *)params { self = [super init]; if (self) { self.state = ChannelClosed; @@ -131,7 +135,7 @@ - (NSString*)replyEventName:(NSString*)ref { return [NSString stringWithFormat:@"chan_reply_%@", ref]; } -- (void)triggerEvent:(NSString*)event message:(id)message ref:(id)ref { +- (void)triggerEvent:(NSString*)event message:(id)message ref:(nullable id)ref { NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSDictionary *binding, NSDictionary *bindings) { return [[binding valueForKey:@"event"] isEqualToString:event]; }]; @@ -147,4 +151,8 @@ - (PhxPush*)pushEvent:(NSString*)event payload:(NSDictionary*)payload { [pushEvent send]; return pushEvent; } + @end + +NS_ASSUME_NONNULL_END + diff --git a/Pod/Classes/PhxChannel_Private.h b/Pod/Classes/PhxChannel_Private.h index 80cd8ee..6ed6b3a 100644 --- a/Pod/Classes/PhxChannel_Private.h +++ b/Pod/Classes/PhxChannel_Private.h @@ -8,13 +8,17 @@ #import +NS_ASSUME_NONNULL_BEGIN + @class PhxChannel; @interface PhxChannel () - (void)rejoin; -- (void)triggerEvent:(NSString*)event message:(id)message ref:(id)ref; +- (void)triggerEvent:(NSString*)event message:(id)message ref:(nullable id)ref; - (BOOL)isMemberOfTopic:(NSString*)topic; - (NSString*)replyEventName:(NSString*)ref; -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxPush.h b/Pod/Classes/PhxPush.h index e528f05..22cb7aa 100644 --- a/Pod/Classes/PhxPush.h +++ b/Pod/Classes/PhxPush.h @@ -9,17 +9,21 @@ #import #import "PhxTypes.h" +NS_ASSUME_NONNULL_BEGIN + @class PhxChannel; @interface PhxPush : NSObject -- (id)initWithChannel:(PhxChannel*)channel - event:(NSString*)event - payload:(NSDictionary*)payload; +- (instancetype)initWithChannel:(PhxChannel*)channel + event:(NSString*)event + payload:(NSDictionary*)payload; - (void)send; -- (PhxPush*)onReceive:(NSString*)status callback:(OnMessage)callback; -- (PhxPush*)after:(int)ms callback:(After)callback; +- (PhxPush *)onReceive:(NSString *)status callback:(OnMessage)callback; +- (PhxPush *)after:(NSTimeInterval)timeInterval callback:(After)callback; @end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/Pod/Classes/PhxPush.m b/Pod/Classes/PhxPush.m index e35966b..267b91f 100644 --- a/Pod/Classes/PhxPush.m +++ b/Pod/Classes/PhxPush.m @@ -11,37 +11,35 @@ #import "PhxChannel_Private.h" #import "PhxSocket.h" +NS_ASSUME_NONNULL_BEGIN + @interface PhxPush () @property (nonatomic, weak) PhxChannel *channel; -@property (nonatomic, retain) NSString *event; -@property (nonatomic, retain) NSString *refEvent; -@property (nonatomic, retain) NSDictionary *payload; +@property (nonatomic, strong) NSString *event; +@property (nonatomic, strong) NSString *refEvent; +@property (nonatomic, strong) NSDictionary *payload; -@property (nonatomic, copy) After afterHook; -@property (readwrite) int afterInterval; -@property (nonatomic, retain) NSTimer *afterTimer; +@property (nullable, nonatomic, copy) After afterHook; +@property (nonatomic) NSTimeInterval afterInterval; +@property (nullable, nonatomic, strong) NSTimer *afterTimer; -@property (nonatomic, retain) NSMutableArray *recHooks; -@property (nonatomic, retain) id receivedResp; -@property (readwrite) BOOL sent; +@property (nonatomic, strong) NSMutableArray *recHooks; +@property (nullable, nonatomic, strong) id receivedResp; +@property (atomic) BOOL sent; @end @implementation PhxPush -- (id)initWithChannel:(PhxChannel*)channel - event:(NSString*)event - payload:(NSDictionary*)payload { +- (instancetype)initWithChannel:(PhxChannel*)channel + event:(NSString*)event + payload:(NSDictionary*)payload { self = [super init]; if (self) { self.channel = channel; self.event = event; - if (payload) { - self.payload = payload; - } else { - self.payload = @{}; - } + self.payload = payload; self.receivedResp = nil; self.afterHook = nil; self.recHooks = [NSMutableArray new]; @@ -51,7 +49,7 @@ - (id)initWithChannel:(PhxChannel*)channel } - (void)send { - const NSString *ref = [self.channel.socket makeRef]; + NSString *ref = [self.channel.socket makeRef]; self.refEvent = [self.channel replyEventName:ref]; self.receivedResp = nil; self.sent = NO; @@ -76,12 +74,16 @@ - (PhxPush*)onReceive:(NSString *)status callback:(OnMessage)callback { return self; } -- (PhxPush*)after:(int)ms callback:(After)callback { +- (PhxPush*)after:(NSTimeInterval)timeInterval callback:(After)callback { if (self.afterHook) { // ERROR } - self.afterTimer = [NSTimer scheduledTimerWithTimeInterval:ms target:self selector:@selector(afterTimerFire:) userInfo:nil repeats:NO]; - self.afterInterval = ms; + self.afterTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval + target:self + selector:@selector(afterTimerFire:) + userInfo:nil + repeats:NO]; + self.afterInterval = timeInterval; self.afterHook = callback; return self; } @@ -129,3 +131,5 @@ - (void)matchReceive:(NSDictionary*)payload { } @end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxPush_Private.h b/Pod/Classes/PhxPush_Private.h index 492ed0d..28f58de 100644 --- a/Pod/Classes/PhxPush_Private.h +++ b/Pod/Classes/PhxPush_Private.h @@ -8,9 +8,12 @@ #import +NS_ASSUME_NONNULL_BEGIN @interface PhxPush() -@property (nonatomic, retain) NSDictionary *payload; +@property (nonatomic, strong) NSDictionary *payload; -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxSocket.h b/Pod/Classes/PhxSocket.h index c44eeca..48e819d 100644 --- a/Pod/Classes/PhxSocket.h +++ b/Pod/Classes/PhxSocket.h @@ -9,6 +9,8 @@ #import #import "PhxTypes.h" +NS_ASSUME_NONNULL_BEGIN + @protocol PhxSocketDelegate - (void)phxSocketDidOpen; @@ -22,13 +24,13 @@ @interface PhxSocket : NSObject @property (nonatomic, weak) id delegate; -@property (nonatomic, readwrite) BOOL reconnectOnError; +@property (nonatomic) BOOL reconnectOnError; -- (id)initWithURL:(NSURL*)url; -- (id)initWithURL:(NSURL*)url heartbeatInterval:(int)interval; +- (instancetype)initWithURL:(NSURL*)url; +- (instancetype)initWithURL:(NSURL*)url heartbeatInterval:(NSTimeInterval)interval; - (void)connect; -- (void)connectWithParams:(NSDictionary*)params; +- (void)connectWithParams:(nullable NSDictionary*)params; - (void)disconnect; - (void)reconnect; @@ -47,3 +49,5 @@ - (void)push:(NSDictionary*)data; @end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxSocket.m b/Pod/Classes/PhxSocket.m index 2578a44..776d6bf 100644 --- a/Pod/Classes/PhxSocket.m +++ b/Pod/Classes/PhxSocket.m @@ -13,39 +13,41 @@ #import "PhxChannel_Private.h" #import "NSDictionary+QueryString.h" -static NSTimeInterval reconnectInterval = 5; +NS_ASSUME_NONNULL_BEGIN + +static NSTimeInterval kReconnectInterval = 5; @interface PhxSocket () -@property (nonatomic, retain) SRWebSocket *socket; -@property (nonatomic, retain) NSURL *URL; -@property (nonatomic, assign) int heartbeatInterval; +@property (nullable, nonatomic) SRWebSocket *socket; +@property (nonatomic, strong) NSURL *URL; +@property (nonatomic) NSTimeInterval heartbeatInterval; -@property (nonatomic, retain) NSMutableArray *channels; +@property (nonatomic, strong) NSMutableArray *channels; @property (nonatomic, strong) NSOperationQueue *queue; -@property (nonatomic, retain) NSTimer *sendBufferTimer; -@property (nonatomic, retain) NSTimer *reconnectTimer; -@property (nonatomic, retain) NSTimer *heartbeatTimer; +@property (nonatomic, strong) NSTimer *sendBufferTimer; +@property (nullable, nonatomic, strong) NSTimer *reconnectTimer; +@property (nullable, nonatomic, strong) NSTimer *heartbeatTimer; -@property (nonatomic, retain) NSMutableArray *openCallbacks; -@property (nonatomic, retain) NSMutableArray *closeCallbacks; -@property (nonatomic, retain) NSMutableArray *errorCallbacks; -@property (nonatomic, retain) NSMutableArray *messageCallbacks; +@property (nonatomic, strong) NSMutableArray *openCallbacks; +@property (nonatomic, strong) NSMutableArray *closeCallbacks; +@property (nonatomic, strong) NSMutableArray *errorCallbacks; +@property (nonatomic, strong) NSMutableArray *messageCallbacks; -@property (nonatomic, retain) NSDictionary *params; +@property (nullable, nonatomic) NSDictionary *params; -@property (readwrite) int ref; +@property int ref; @end @implementation PhxSocket -- (id)initWithURL:(NSURL*)url { +- (instancetype)initWithURL:(NSURL*)url { return [self initWithURL:url heartbeatInterval:0]; } -- (id)initWithURL:(NSURL*)url heartbeatInterval:(int)interval { +- (instancetype)initWithURL:(NSURL*)url heartbeatInterval:(NSTimeInterval)interval { self = [super init]; if (self) { self.URL = url; @@ -70,7 +72,7 @@ - (void)connect { [self connectWithParams:nil]; } -- (void)connectWithParams:(NSDictionary*)params { +- (void)connectWithParams:(nullable NSDictionary*)params { NSURL *url; self.params = params; if (self.params != nil) { @@ -211,7 +213,11 @@ - (void)onConnClose:(id)event { if (self.reconnectOnError) { [self discardReconnectTimer]; - self.reconnectTimer = [NSTimer scheduledTimerWithTimeInterval:reconnectInterval target:self selector:@selector(reconnect) userInfo:nil repeats:YES]; + self.reconnectTimer = [NSTimer scheduledTimerWithTimeInterval:kReconnectInterval + target:self + selector:@selector(reconnect) + userInfo:nil + repeats:YES]; } [self discardHeartbeatTimer]; @@ -302,3 +308,5 @@ - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reas } @end + +NS_ASSUME_NONNULL_END diff --git a/Pod/Classes/PhxSocket_Private.h b/Pod/Classes/PhxSocket_Private.h index e60be2e..c1f8744 100644 --- a/Pod/Classes/PhxSocket_Private.h +++ b/Pod/Classes/PhxSocket_Private.h @@ -8,7 +8,7 @@ #import - +NS_ASSUME_NONNULL_BEGIN @class PhxSocket; @class PhxChannel; @@ -18,4 +18,6 @@ - (void)addChannel:(PhxChannel*)channel; - (void)removeChannel:(PhxChannel*)channel; -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END