So I was building a flutter native plugin. I have two method (in xyzPlugin.m
) which looks like this
+ (void)registerWithRegistrar:(nonnull NSObject<FlutterPluginRegistrar> *)registrar {
and
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
Now, I want to share instance variable between both of them.
Suppose. I initialize meetingView
like this inside registerWithRegistrar
MeetingView *meetingView = [MeetingView new];
How can I use the same in handleMethodCall
?
What have I tried?
@implementation xyzPlugin {
MeetingView *_view;
}
and then in
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
_view = [MeetingView new];
but this gives following error
Instance variable ‘_view’ accessed in class method
2
Answers
Maybe you need a global variable, so you can claim your object with a
static
keyword like:then you can access this object in between class methods in Objective-C.