Home > Mobile >  Beginners to ask questions about nsarray variable size distribution
Beginners to ask questions about nsarray variable size distribution

Time:10-20

There is such a piece of code, for example:
In. H gave it to a class in the attribute
@ interface groupmodel: NSObject

@ property (nonatomic, copy) NSArray * friends;

Then in. M wrote in a set of methods:
- (void) setFriends friends: (NSArray *)
{
NSMutableArray * data=https://bbs.csdn.net/topics/[NSMutableArray array];

For (NSDictionary * dictdata in friends)
{
Init groupmodel * model=[[groupmodel alloc]].

[model setValuesForKeysWithDictionary: dictdata];

[data addObject: model];
}

_friends=[data copy];

}

Excuse me this kind of situation, nsarray * friends at first and no size distribution data? Or what mechanism? thank you

CodePudding user response:

Apple's attribute declarations, @ property mechanism will help you to create a default _ at the beginning, the internal variables with the same name
The default generated and get and set methods (external are accessed through these two methods).

You name the properties of the friends, so there is a internal variables called _friends
You rewrite the - (void) setFriends friends: (NSArray *) method, the method creates an array in
NSMutableArray * data=https://bbs.csdn.net/topics/[NSMutableArray array];
Here has been allocated space
In the end you put this attribute _friends points to the array data
_friends=[data copy];
So your friends are your data in the method, thus know where space
  •  Tags:  
  • iOS
  • Related