Skip to content

Commit

Permalink
iOS: Make FlutterViewController.engine a strong ref (#56663)
Browse files Browse the repository at this point in the history
Previously, FlutterViewController.engine was declared as a weak readonly property, but we explicitly declared the `FlutterEngine* _engine` ivar as a strong reference in the implementation. This changes the property declaration to be strong and eliminates the now unnecessary ivar.

There is also no semantic change to FlutterViewController itself, since the `_engine` ivar had been manually declared as a strong reference.

There is no semantic change for users of FlutterViewController.engine since whether a user acquires a strong or weak reference to the engine is determined by whether they declare the pointer to which they assign it as strong or weak.

This also eliminates the need for the `engine` getter, which was only present to prevent a warning that the strong ivar didn't match the weak property declaration.

No changes to tests since this introduces no semantic changes.

Issue: flutter/flutter#137801

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
cbracken authored Nov 17, 2024
1 parent e86b989 commit 7846bc2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ FLUTTER_DARWIN_EXPORT
* `FlutterViewController` is initialized with or a new `FlutterEngine` implicitly created if
* no engine was supplied during initialization.
*/
@property(weak, nonatomic, readonly) FlutterEngine* engine;
@property(nonatomic, readonly) FlutterEngine* engine;

/**
* The `FlutterBinaryMessenger` associated with this FlutterViewController (used for communicating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ - (void)handleKeyboardAnimationCallbackWithTargetTime:(fml::TimePoint)targetTime
@end

@implementation FlutterViewController {
FlutterEngine* _engine;
flutter::ViewportMetrics _viewportMetrics;
MouseState _mouseState;
}
Expand Down Expand Up @@ -302,10 +301,6 @@ - (void)performCommonViewControllerInitialization {
[self setUpNotificationCenterObservers];
}

- (FlutterEngine*)engine {
return _engine;
}

- (void)setUpNotificationCenterObservers {
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
Expand Down

0 comments on commit 7846bc2

Please sign in to comment.