Skip to content

Commit

Permalink
__unsafe_unretained
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman committed Apr 12, 2024
1 parent 1c293d9 commit 92daaec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ @interface FlutterKeyboardManager ()
/**
* The primary responders added by addPrimaryResponder.
*/
@property(nonatomic, readonly) NSMutableArray<id<FlutterKeyPrimaryResponder>>* primaryResponders;
@property(nonatomic, copy, readonly)
NSMutableArray<id<FlutterKeyPrimaryResponder>>* primaryResponders;

/**
* The secondary responders added by addSecondaryResponder.
*/
@property(nonatomic, readonly)
@property(nonatomic, copy, readonly)
NSMutableArray<id<FlutterKeySecondaryResponder>>* secondaryResponders;

- (void)dispatchToSecondaryResponders:(nonnull FlutterUIPressProxy*)press
Expand Down Expand Up @@ -49,11 +50,6 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
[_secondaryResponders addObject:responder];
}

- (void)dealloc {
[_primaryResponders removeAllObjects];
[_secondaryResponders removeAllObjects];
}

- (void)handlePress:(nonnull FlutterUIPressProxy*)press
nextAction:(nonnull void (^)())next API_AVAILABLE(ios(13.4)) {
if (@available(iOS 13.4, *)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ @implementation FlutterKeyboardManagerTest
OCMStrictProtocolMock(@protocol(FlutterKeyPrimaryResponder));
OCMStub([mock handlePress:[OCMArg any] callback:[OCMArg any]])
.andDo((^(NSInvocation* invocation) {
__unsafe_unretained FlutterUIPressProxy* press;
__unsafe_unretained FlutterAsyncKeyCallback callback;
[invocation getArgument:&press atIndex:2];
[invocation getArgument:&callback atIndex:3];
__unsafe_unretained FlutterUIPressProxy* pressUnsafe;
__unsafe_unretained FlutterAsyncKeyCallback callbackUnsafe;

[invocation getArgument:&pressUnsafe atIndex:2];
[invocation getArgument:&callbackUnsafe atIndex:3];

// Retain the unretained parameters so they can
// be run in the perform block when this invocation goes out of scope.
FlutterUIPressProxy* press = pressUnsafe;
FlutterAsyncKeyCallback callback = callbackUnsafe;
CFRunLoopPerformBlock(CFRunLoopGetCurrent(),
fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, ^() {
callbackSetter(press, callback);
Expand Down

0 comments on commit 92daaec

Please sign in to comment.