Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C, what [NSString initWithFormat] exactly does?
    primarykey
    data
    text
    <p>I just would like to know the difference between the line 1 and 2 bellow:</p> <pre><code>_subtitle = @"Test"; //Line 1 _subtitle = [NSString stringWithFormat: @"Test"]; //Line 2 </code></pre> <p>If I asked that question, it is because I got a problem by using MKAnnotation. In the method bellow, I try to update the subtitle delegate property of MKAnnotation (which is nonatomic, copy and readonly). But it's look like that I got a zombie when using the line 2 and nothing when using the line 1. So my question is why?</p> <pre><code>- (void) initCoordinateWithAddress:(NSString*)address; { self.address = address; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString: address completionHandler:^(NSArray *placemarks,NSError *error) { CLPlacemark *place = [placemarks objectAtIndex:0]; _coordinate = place.location.coordinate; _title = self.address; _subtitle = @"Test"; //Line 1: don't crash _subtitle = [NSString stringWithFormat: @"Test"]; //Line 2: crash //_subtitle = [[NSString stringWithFormat: @"[%.2f,%.2f]", self.coordinate.latitude, self.coordinate.longitude] copy]; _isInit = YES; [self.customDelegate didCalculateCoordinate: place.location.coordinate forAnnotation: self]; }]; </code></pre> <p>}</p> <p>I actually already fixed my problem by using the method copy, but I still not understand what is the difference between the line 1 and 2, if anyone can help me to understand what the difference is, I will appreciate.</p> <p>Edit: </p> <p>1- I am not using ARC</p> <p>2- _subtitle comes form @synthesize subtitle = _subtitle; And subtitle is a part of the MKAnnotation protocol, with the property nonatomic, readonly and copy</p> <p>Regards, Cyril</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload