The tutorial I am working on has the following method defined.
- (void)addBirdSightingWithSighting:(BirdSighting *)sighting {
[self.masterBirdSightingList addObject:sighting];
}
The tutorial describes this as follows:
This method creates and initializes a new
BirdSightingobject by sending to theinitWithName:location:date:method the name and location the user entered, along with today’s date. Then, the method adds the newBirdSightingobject to the array.
There is a initWithName:location:date: method that is on the BirdSighting class which is my data model. The above method is added to the data controller which simply is adding a BirdSighting object to the masterBirdSightingList mutable array.
What I do not understand is that the tutorial says that BirdSighting object is sent to the initWithName:location:date: method when I do not see this?
- Is this because the
*in the(BirdSighting *)method parameter? I understand that the*is a pointer to a object, but does it create a new object and call its default init method? And just because I added theinitWithName:location:dateto theBirdSightingclass, does it automatically become my defaultinitmethod?
No magic there. You’re right. That line of code does not create or initialize a BirdSighting object.
Added:
You’ve discovered, perhaps sooner than many, that neither the Apple code nor docs are perfect. Sometimes they even have serious issues. When you encounter a dissonance, it’s best to trust your intuition and do some of your own testing.