google / google/GoogleSignIn-iOS

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

オープン
#232 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Objective-C
スター
750
フォーク
282
平均マージ
2日 15時間
マージ済み PR(30日)
9

説明

**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
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。