google / google/GoogleSignIn-iOS

Reconsider our usage of dereference and access arrow operator (`->`)

Đang mở
#232 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Objective-C
Star
750
Fork
282
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

**Is your feature request related to a problem you're having? Please describe.**

We should consider replacing the usage of the arrow operator in our codebase. Doing so would, in many cases, make our code easier to read and in some cases make for less code in general. See the "Additional Context" below.

**Describe the solution you'd like**

Replace the use of `->` with property access through `self`.

**Describe alternatives you've considered**

We could leave things as they are, but this would push the "problem" into the future.

**Additional context**

Here is an example of the enhancement I am thinking of, which arose in conversation during the review of [#230](https://github.com/google/GoogleSignIn-iOS/pull/230#discussion_r983897020). The suggestion below replaces the use of `self->_delegate` with `weakSelf.delegate`. Note that in cases where we are confident that there is no strong reference cycle in the block, we could simply use `self.delegate` as we do in `self->_delegate`. The example below also obviates the need for `GTMAppAuthFetcherAuthorizationEMMChainedDelegate *_retained_self;`, which is used within the preexisting code moved in #230.

```
#pragma mark - GTMAppAuthFetcherAuthorizationEMMChainedDelegate

@interface GTMAppAuthFetcherAuthorizationEMMChainedDelegate ()

@property (weak, nonatomic) id delegate;
@property (nonatomic) SEL selector;

@end

@implementation GTMAppAuthFetcherAuthorizationEMMChainedDelegate

- (instancetype)initWithDelegate:(id)delegate selector:(SEL)selector {
self = [super init];
if (self) {
_delegate = delegate;
_selector = selector;
}
return self;
}

- (void)authentication:(GTMAppAuthFetcherAuthorization *)auth
request:(NSMutableURLRequest *)request
finishedWithError:(nullable NSError *)error {
__weak GTMAppAuthFetcherAuthorizationEMMChainedDelegate *weakSelf = self;
[GIDAppAuthFetcherAuthorizationWithEMMSupport handleTokenFetchEMMError:error
completion:^(NSError *_Nullable error) {
if (weakSelf.delegate || weakSelf.selector) {
return;
}
NSMethodSignature *signature = [weakSelf.delegate methodSignatureForSelector:weakSelf.selector];
if (!signature) {
return;
}
id argument1 = auth;
id argument2 = request;
id argument3 = error;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:weakSelf.delegate]; // index 0
[invocation setSelector:weakSelf.selector]; // index 1
[invocation setArgument:&argument1 atIndex:2];
[invocation setArgument:&argument2 atIndex:3];
[invocation setArgument:&argument3 atIndex:4];
[invocation invoke];
}];
}

@end
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.