objective c - Can't access to extern variable from another class -
i've created phonegap plugin give variable native code. works fine. need access value other classes decided create extern nsstring.
.h
extern nsstring *lkwid; @interface myplugin : cdvplugin { } @property (retain, nonatomic) nsstring *lkwid; -(void) setmyvalue:(nsmutablearray*)arguments withdict:(nsmutabledictionary*)options; .m
#import "myplugin.h" @implementation myplugin @synthesize lkwid; nsstring *lkwid = @""; -(void) setmyvalue:(nsmutablearray*)arguments withdict:(nsmutabledictionary*)options { nsstring* callbackid = [arguments objectatindex:1]; lkwid = callbackid; nslog(@"set value %@ ",lkwid); //nslog shows correct value javascript } now want access lkwid mainviewcontroller.m (myplugin.h imported) lkwid empty. why?
i think confusing instance variables , static (class) variables. extern nsstring *lkwid declares globally accessible variable. @property (retain,nonatomic) nsstring *lkwid declares instance variables object. if want set global variable, shared all instances, should not synthesize property andimplement getter , setter in following manner:
- (nsstring*) lkwid { return lkwid; } - (void) setlkwid:(nsstring*)value { lkwid = value; } make sure don't declare instance variable name lkwid.
Comments
Post a Comment