From 92daaecb433d4434d33d9109ea638a9495a983bb Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 11 Apr 2024 21:31:16 -0700 Subject: [PATCH] __unsafe_unretained --- .../ios/framework/Source/FlutterKeyboardManager.mm | 10 +++------- .../framework/Source/FlutterKeyboardManagerTest.mm | 14 ++++++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm b/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm index b2400e2f6d837..83d1e22a1aabe 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm @@ -16,12 +16,13 @@ @interface FlutterKeyboardManager () /** * The primary responders added by addPrimaryResponder. */ -@property(nonatomic, readonly) NSMutableArray>* primaryResponders; +@property(nonatomic, copy, readonly) + NSMutableArray>* primaryResponders; /** * The secondary responders added by addSecondaryResponder. */ -@property(nonatomic, readonly) +@property(nonatomic, copy, readonly) NSMutableArray>* secondaryResponders; - (void)dispatchToSecondaryResponders:(nonnull FlutterUIPressProxy*)press @@ -49,11 +50,6 @@ - (void)addSecondaryResponder:(nonnull id)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, *)) { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm index 0cf1f07026aae..7ebd7c01a3ace 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm @@ -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);