ios - Proper way to manage the array -
i using mutable array . not sure correct way of managing array. tried learn memory management basics,but found difficult grasp. doing is
declaring array @ interface
@interface myvc() @property (nonatomic,strong) nsmutablearray *substrings; // if use weak attribute here,does change anything? @end -(void)mymethod{ // initializing array _substrings=[[nsmutablearray alloc]init]; //storing data [_substrings addobject:@"hello"]; //do data in array //call method gets data same array , operations there [self method2];-----> // access data array like, x=[_substrings objectatindex:0]; //finally, remove items in array [_substrings removeobject:@"hello"]; //and again start process mentioned here }
this thinking do. proper way of declaring , accesssing , managing array?
in general work, recommend access array using property getter/setter. way if ever need create custom getter/setter not need refactor code.
@interface myvc() @property (nonatomic, strong) nsmutablearray *substrings; @end -(void)mymethod{ // initializing array _substrings=[[nsmutablearray alloc]init]; //storing data [self.substrings addobject:@"hello"]; [self method2];-----> // access data array like, x=[self.substrings objectatindex:0]; //finally, remove items in array [self.substrings removeobject:@"hello"]; }
Comments
Post a Comment