objective c - I need these three stock options to be class level variables, so they are only declared and initialised once -
i need 3 stock options below declared , initialised once. have got pseudo-code achieve i'm unsure on how make work.
this declared in .m
file of ios app , nothing in .h
file .
pseudo-code below:
// _msftstockprice _googstockprice _applstockprice need class level if(_msftstrockprice == nil) googstockprice = [[[cpdstockpricestore sharedinstance] monthlyprices:cpdtickersymbolmsft] if(_applestrockprice == nil) _msftstockprice = [[[cpdstockpricestore sharedinstance] monthlyprices:cpdtickersymbolmsft] if(_msftstrockprice == nil) msftstockprice = [[[cpdstockpricestore sharedinstance] monthlyprices:cpdtickersymbolmsft] if ([plot.identifier isequal:cpdtickersymbolaapl] == yes) { return [_applestockprice objectatindex:index]; } else if ([plot.identifier isequal:cpdtickersymbolgoog] == yes) { return [[_googstockprice objectatindex:index]; } else if ([plot.identifier isequal:cpdtickersymbolmsft] == yes) { return [_msftstockprice objectatindex:index]; }
don't declare variables properties or instance variables, rather static variables. either in top scope of .m file, or if methods above place variables accessed, right inside method. so:
static nsarray *anarray=nil;
static variables visible instances of class. depending on design (threads) need guard against problems caused concurrent access.
Comments
Post a Comment