0
我正在使用可變數組。我不確定這是否是管理陣列的正確方法。我試圖學習內存管理的基礎知識,但我發現它很難掌握。我做的是管理陣列的正確方法
聲明數組在界面
@interface myVC()
@property (nonatomic,strong) NSMutableArray *substrings; // if I use weak attribute here,does it change anything?
@end
-(void)myMethod{
// initializing the array
_substrings=[[NSMutableArray alloc]init];
//storing some data into it
[_substrings addObject:@"hello"];
//do something with the data in that array
//call another method which gets the data from this same array and do some operations there
[self method2];-----> // I access data from the array like, x=[_substrings objectatindex:0];
//finally, remove the items in the array
[_substrings removeObject:@"hello"];
//and again start the process as mentioned here
}
這是我在想什麼做的。這是聲明和訪問和管理數組的正確方法嗎?