The main line of iOS code to explain the code

tutorial I am working on defining the following method.

- (void)addBirdSightingWithSighting:(BirdSighting *)sighting { [self.masterBirdSightingList addObject:sighting]; } 

The tutorial describes the following:

This method creates and initializes a new BirdSighting object by sending the initWithName:location:date: name and location the user entered along with the current date to the initWithName:location:date: . This method then adds a new BirdSighting object to the array.

There is an initWithName:location:date: method, which is in the BirdSighting class, which is my data model. The above method is added to the data controller, which simply adds the BirdSighting object to the BirdSighting variable array.

I donโ€™t understand that the tutorial says that the BirdSighting object BirdSighting sent to the initWithName:location:date: method when I donโ€™t see it?

  • Is it because * in the method parameter (BirdSighting *) ? I understand that * is a pointer to an object, but does it create a new object and call its init method by default? And just because I added the initWithName:location:date class to the BirdSighting class, did it automatically become the default init method?
+4
source share
1 answer

There is no magic. You're right. This line of code does not create or initialize a BirdSighting object.

Added:

You have discovered, perhaps before many, that neither the Apple code nor the documents are perfect. Sometimes they even have serious problems. When you come across dissonance, it is best to trust your intuition and perform some of your own tests.

+2
source

All Articles