i want create global variable coordinates uiview how correct syntax this?
first need create nsobject class
give class name globalshareclass
globalshareclass.h
#import <foundation/foundation.h> @interface globalshareclass : nsobject { } @property (nonatomic) float xvalue @property (nonatomic) float yvalue + (globalshareclass *)sharedinstance; @end
globalshareclas.m
#import "globalshareclass.h" static globalshareclass *_shareinstane; @implementation globalshareclass @synthesize xvalue; @synthesize yvalue; + (globalshareclass *)sharedinstance { if (_shareinstane == nil) { _shareinstane = [[globalshareclass alloc] init]; } return _shareinstane; }
viewcontroller.h
#import <uikit/uikit.h> #import "globalshareclass.h" @interface viewcontroller : uiviewcontroller { globalshareclass *globalshare; } @end;
viewcontroller.m
#import "viewcontroller.h" @interface viewcontroller () @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. globalshare = [globalshareclass sharedinstance]; globalshare.xvalue = 50.0; globalshare.xvalue = 100.0; }
Comments
Post a Comment