Skip to content

Commit

Permalink
Add comment explaining __unsafe_unretained usage
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox committed Nov 10, 2021
1 parent b086aa0 commit 7031d9a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Source/santametricservice/Writers/SNTMetricHTTPWriterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ - (void)setUp {
self.httpWriter = [[SNTMetricHTTPWriter alloc] init];
self.mockResponses = [[NSMutableArray alloc] init];

// This must be marked __unsafe_unretained because we're going to store into
// it using NSInvocation's getArgument:atIndex: method which takes a void*
// to populate. If we don't mark the variable __unsafe_unretained it will
// default to __strong and ARC will attempt to release the block when it goes
// out of scope, not knowing that it wasn't ours to release in the first place.
__unsafe_unretained __block void (^completionHandler)(NSData *, NSURLResponse *, NSError *);

void (^getCompletionHandler)(NSInvocation *) = ^(NSInvocation *invocation) {
Expand Down

0 comments on commit 7031d9a

Please sign in to comment.