Kaynağa Gözat

Use instancetype instead of id for return types of init methods.

Nikita Lutsenko 9 yıl önce
ebeveyn
işleme
e4101f6ad1

+ 13 - 13
SRWebSocketTests/SRTAutobahnTests.m

@@ -22,12 +22,12 @@
 @end
 @end
 
 
 @interface TestOperation : SRTWebSocketOperation <SRWebSocketDelegate>
 @interface TestOperation : SRTWebSocketOperation <SRWebSocketDelegate>
-- (id)initWithBaseURL:(NSURL *)url testNumber:(NSInteger)testNumber agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url testNumber:(NSInteger)testNumber agent:(NSString *)agent;
 @end
 @end
 
 
 
 
 @interface CaseGetterOperation : SRTWebSocketOperation <SRWebSocketDelegate>
 @interface CaseGetterOperation : SRTWebSocketOperation <SRWebSocketDelegate>
-- (id)initWithBaseURL:(NSURL *)url;
+- (instancetype)initWithBaseURL:(NSURL *)url;
 
 
 @property (nonatomic, readonly) NSInteger caseCount;
 @property (nonatomic, readonly) NSInteger caseCount;
 
 
@@ -41,7 +41,7 @@
 
 
 @interface SRTBlockInvoker
 @interface SRTBlockInvoker
 
 
-- (id)initWithBlock:(dispatch_block_t)block;
+- (instancetype)initWithBlock:(dispatch_block_t)block;
 
 
 - (void)invoke;
 - (void)invoke;
 
 
@@ -49,7 +49,7 @@
 
 
 @interface UpdateOperation : SRTWebSocketOperation <SRWebSocketDelegate>
 @interface UpdateOperation : SRTWebSocketOperation <SRWebSocketDelegate>
 
 
-- (id)initWithBaseURL:(NSURL *)url agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url agent:(NSString *)agent;
 
 
 @end
 @end
 
 
@@ -57,7 +57,7 @@
 
 
 @property (nonatomic) NSDictionary *info;
 @property (nonatomic) NSDictionary *info;
 
 
-- (id)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber;
+- (instancetype)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber;
 
 
 @end
 @end
 
 
@@ -65,7 +65,7 @@
 
 
 @property (nonatomic) NSDictionary *info;
 @property (nonatomic) NSDictionary *info;
 
 
-- (id)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber agent:(NSString *)agent;
 
 
 @end
 @end
 
 
@@ -80,7 +80,7 @@
     NSString *_description;
     NSString *_description;
 }
 }
 
 
-- (id)initWithInvocation:(NSInvocation *)anInvocation description:(NSString *)description;
+- (instancetype)initWithInvocation:(NSInvocation *)anInvocation description:(NSString *)description;
 {
 {
     self = [self initWithInvocation:anInvocation];
     self = [self initWithInvocation:anInvocation];
     if (self) {
     if (self) {
@@ -89,7 +89,7 @@
     return self;
     return self;
 }
 }
 
 
-- (id)initWithInvocation:(NSInvocation *)anInvocation;
+- (instancetype)initWithInvocation:(NSInvocation *)anInvocation;
 {
 {
     self = [super initWithInvocation:anInvocation];
     self = [super initWithInvocation:anInvocation];
     if (self) {
     if (self) {
@@ -233,7 +233,7 @@
     NSInteger _testNumber;
     NSInteger _testNumber;
 }
 }
 
 
-- (id)initWithBaseURL:(NSURL *)url testNumber:(NSInteger)testNumber agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url testNumber:(NSInteger)testNumber agent:(NSString *)agent;
 {   
 {   
     
     
     NSString *path = [[url URLByAppendingPathComponent:@"runCase"] absoluteString];
     NSString *path = [[url URLByAppendingPathComponent:@"runCase"] absoluteString];
@@ -258,7 +258,7 @@
 
 
 @synthesize caseCount = _caseCount;
 @synthesize caseCount = _caseCount;
 
 
-- (id)initWithBaseURL:(NSURL *)url;
+- (instancetype)initWithBaseURL:(NSURL *)url;
 {
 {
     self = [super initWithURL:[url URLByAppendingPathComponent:@"getCaseCount"]];
     self = [super initWithURL:[url URLByAppendingPathComponent:@"getCaseCount"]];
     if (self) {
     if (self) {
@@ -276,7 +276,7 @@
 
 
 @implementation UpdateOperation
 @implementation UpdateOperation
 
 
-- (id)initWithBaseURL:(NSURL *)url agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url agent:(NSString *)agent;
 {
 {
     NSString *path = [[url URLByAppendingPathComponent:@"updateReports"] absoluteString];
     NSString *path = [[url URLByAppendingPathComponent:@"updateReports"] absoluteString];
     path = [path stringByAppendingFormat:@"?agent=%@", agent];
     path = [path stringByAppendingFormat:@"?agent=%@", agent];
@@ -297,7 +297,7 @@
 
 
 @synthesize info = _info;
 @synthesize info = _info;
 
 
-- (id)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber;
+- (instancetype)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber;
 {
 {
     NSString *path = [[url URLByAppendingPathComponent:@"getCaseInfo"] absoluteString];
     NSString *path = [[url URLByAppendingPathComponent:@"getCaseInfo"] absoluteString];
     path = [path stringByAppendingFormat:@"?case=%@", @(caseNumber)];
     path = [path stringByAppendingFormat:@"?case=%@", @(caseNumber)];
@@ -317,7 +317,7 @@
 
 
 @synthesize info = _info;
 @synthesize info = _info;
 
 
-- (id)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber agent:(NSString *)agent;
+- (instancetype)initWithBaseURL:(NSURL *)url caseNumber:(NSInteger)caseNumber agent:(NSString *)agent;
 {
 {
     NSString *path = [[url URLByAppendingPathComponent:@"getCaseStatus"] absoluteString];
     NSString *path = [[url URLByAppendingPathComponent:@"getCaseStatus"] absoluteString];
     path = [path stringByAppendingFormat:@"?case=%@&agent=%@", @(caseNumber), agent];
     path = [path stringByAppendingFormat:@"?case=%@&agent=%@", @(caseNumber), agent];

+ 1 - 1
SRWebSocketTests/SRTWebSocketOperation.h

@@ -12,7 +12,7 @@
 
 
 @interface SRTWebSocketOperation : NSOperation <SRWebSocketDelegate>
 @interface SRTWebSocketOperation : NSOperation <SRWebSocketDelegate>
 
 
-- (id)initWithURL:(NSURL *)URL;
+- (instancetype)initWithURL:(NSURL *)URL;
 
 
 @property (nonatomic) BOOL isFinished;
 @property (nonatomic) BOOL isFinished;
 @property (nonatomic) BOOL isExecuting;
 @property (nonatomic) BOOL isExecuting;

+ 1 - 1
SRWebSocketTests/SRTWebSocketOperation.m

@@ -22,7 +22,7 @@
 @synthesize isExecuting = _isExecuting;
 @synthesize isExecuting = _isExecuting;
 @synthesize error = _error;
 @synthesize error = _error;
 
 
-- (id)initWithURL:(NSURL *)URL;
+- (instancetype)initWithURL:(NSURL *)URL;
 {
 {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {

+ 6 - 6
SocketRocket/SRWebSocket.h

@@ -72,14 +72,14 @@ extern NSString *const SRHTTPResponseErrorKey;
 @property (nonatomic, readonly, copy) NSString *protocol;
 @property (nonatomic, readonly, copy) NSString *protocol;
 
 
 // Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
 // Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
-- (id)initWithURLRequest:(NSURLRequest *)request;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
 
 
 // Some helper constructors.
 // Some helper constructors.
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
-- (id)initWithURL:(NSURL *)url;
+- (instancetype)initWithURL:(NSURL *)url;
+- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
+- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
 
 
 // Delegate queue will be dispatch_main_queue by default.
 // Delegate queue will be dispatch_main_queue by default.
 // You cannot set both OperationQueue and dispatch_queue.
 // You cannot set both OperationQueue and dispatch_queue.

+ 10 - 10
SocketRocket/SRWebSocket.m

@@ -163,7 +163,7 @@ typedef void (^data_callback)(SRWebSocket *webSocket,  NSData *data);
 // This class is not thread-safe, and is expected to always be run on the same queue.
 // This class is not thread-safe, and is expected to always be run on the same queue.
 @interface SRIOConsumerPool : NSObject
 @interface SRIOConsumerPool : NSObject
 
 
-- (id)initWithBufferCapacity:(NSUInteger)poolSize;
+- (instancetype)initWithBufferCapacity:(NSUInteger)poolSize;
 
 
 - (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
 - (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
 - (void)returnConsumer:(SRIOConsumer *)consumer;
 - (void)returnConsumer:(SRIOConsumer *)consumer;
@@ -256,7 +256,7 @@ static __strong NSData *CRLFCRLF;
     CRLFCRLF = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
     CRLFCRLF = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
 }
 }
 
 
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates
 {
 {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {
@@ -273,28 +273,28 @@ static __strong NSData *CRLFCRLF;
     return self;
     return self;
 }
 }
 
 
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols
 {
 {
     return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:NO];
     return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:NO];
 }
 }
 
 
-- (id)initWithURLRequest:(NSURLRequest *)request;
+- (instancetype)initWithURLRequest:(NSURLRequest *)request
 {
 {
     return [self initWithURLRequest:request protocols:nil];
     return [self initWithURLRequest:request protocols:nil];
 }
 }
 
 
-- (id)initWithURL:(NSURL *)url;
+- (instancetype)initWithURL:(NSURL *)url;
 {
 {
     return [self initWithURL:url protocols:nil];
     return [self initWithURL:url protocols:nil];
 }
 }
 
 
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
+- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
 {
 {
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];    
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];    
     return [self initWithURLRequest:request protocols:protocols];
     return [self initWithURLRequest:request protocols:protocols];
 }
 }
 
 
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
+- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates
 {
 {
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
     return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:allowsUntrustedSSLCertificates];
     return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:allowsUntrustedSSLCertificates];
@@ -1659,7 +1659,7 @@ static const size_t SRFrameHeaderOverhead = 32;
     NSMutableArray *_bufferedConsumers;
     NSMutableArray *_bufferedConsumers;
 }
 }
 
 
-- (id)initWithBufferCapacity:(NSUInteger)poolSize;
+- (instancetype)initWithBufferCapacity:(NSUInteger)poolSize;
 {
 {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {
@@ -1669,7 +1669,7 @@ static const size_t SRFrameHeaderOverhead = 32;
     return self;
     return self;
 }
 }
 
 
-- (id)init
+- (instancetype)init
 {
 {
     return [self initWithBufferCapacity:8];
     return [self initWithBufferCapacity:8];
 }
 }
@@ -1861,7 +1861,7 @@ static NSRunLoop *networkRunLoop = nil;
     sr_dispatch_release(_waitGroup);
     sr_dispatch_release(_waitGroup);
 }
 }
 
 
-- (id)init
+- (instancetype)init
 {
 {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {

+ 1 - 1
TestChat/TCChatCell.m

@@ -13,7 +13,7 @@
 @synthesize nameLabel = _nameLabel;
 @synthesize nameLabel = _nameLabel;
 @synthesize textView = _textView;
 @synthesize textView = _textView;
 
 
-- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 {
 {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
     if (self) {

+ 2 - 2
TestChat/TCViewController.m

@@ -12,7 +12,7 @@
 
 
 @interface TCMessage : NSObject
 @interface TCMessage : NSObject
 
 
-- (id)initWithMessage:(NSString *)message fromMe:(BOOL)fromMe;
+- (instancetype)initWithMessage:(NSString *)message fromMe:(BOOL)fromMe;
 
 
 @property (nonatomic, retain, readonly) NSString *message;
 @property (nonatomic, retain, readonly) NSString *message;
 @property (nonatomic, readonly)  BOOL fromMe;
 @property (nonatomic, readonly)  BOOL fromMe;
@@ -173,7 +173,7 @@
 @synthesize message = _message;
 @synthesize message = _message;
 @synthesize fromMe = _fromMe;
 @synthesize fromMe = _fromMe;
 
 
-- (id)initWithMessage:(NSString *)message fromMe:(BOOL)fromMe;
+- (instancetype)initWithMessage:(NSString *)message fromMe:(BOOL)fromMe;
 {
 {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {