// targ_url is passed in as an address to a NSString pointer.
- (long) analyse_scan_result : (NSString *)scan_result target_url : (NSString **)targ_url
{
NSLog (@" RES analyse string : %@", scan_result);
NSRange range = [scan_result rangeOfString : @"http://"
options : NSCaseInsensitiveSearch
];
// **** The following retain is the first retain
// **** statement in this method.
if (range.location == NSNotFound)
{
*targ_url = @"";
[*targ_url retain];
NSLog(@" FND string not found");
return 0;
}
NSString *sub_string = [scan_result substringFromIndex : range.location];
range = [sub_string rangeOfString : @" "];
if (range.location != NSNotFound) {
sub_string = [sub_string substringToIndex : range.location];
}
NSLog(@"FND sub_string = %@", sub_string);
*targ_url = sub_string;
// ** The following retain is the second retain
// ** statement in this method.
[*targ_url retain];
return [*targ_url length];
}
This question is similar and related to the one I asked earlier (which seems to be satisfactorily solved). Again, the above method only works after a retain statement is added. There are 2 added above, but only one is executed at any given time.
What the routine does is to find a "http://" string from a barcode scanner output and return it. My question is are the retain statements necessary or appropriate ?
Hope somebody knowledgable could help...