FROM : Craig Bakalian
DATE : Sat Nov 20 12:46:41 2004
Hi,
This is the first time I have made a function call like this, with a
pointer to a pointer -
-(BOOL)isWordInQuestion: (NSString *)word location: (NSString
**)location
{
NSRange r = NSMakeRange(0,0);
NSMutableString *ms = [NSMutableString string];
[ms appendString: [self stringFromRTFDData: [self questionBody]]];
[ms appendString: [self stringFromRTFDData: [self optionOne]]];
[ms appendString: [self stringFromRTFDData: [self optionTwo]]];
[ms appendString: [self stringFromRTFDData: [self optionThree]]];
[ms appendString: [self stringFromRTFDData: [self optionFour]]];
NS_DURING
r = [ms rangeOfString: word];
NS_HANDLER
if ([[localException name] isEqualToString:
NSInvalidArgumentException] ||
[[localException name] isEqualToString: NSRangeException])
{
return NO;
}
NS_ENDHANDLER
if(r.location > 0 && r.length > 0)
{
NSMutableString *s = [NSMutableString string];
[s appendString: [[self test]testName]];
[s appendString: @", "];
[s appendString: [self getQuestionNameAndNumber]];
*location = [s copy];
return YES;
}
else return NO;
}
And then another object iterates through all of the above objects and
calls the above function like so -
- (IBAction)findThisWord:(id)sender
{
NSString *word = [findWordTextField stringValue];
if(![word isEqualToString: @""])
{
for(i=0;i<[allQuestions count]; i++)
{
Question *q = [allQuestions objectAtIndex: i];
BOOL isIn;
NSString *loc =nil;
isIn = [q isWordInQuestion: word location: &loc];
if(loc)NSLog(@"%@", loc);
[loc release];
}
}
}
The big questions is - am I releasing properly, is there any leaking? I
have tested, not thoroughly, but still I am concerned. I am not
throwing and memory erros, but... How does one release, retain, copy,
when using a point to a pointer in Foundation and Objective C?
Craig Bakalian
www.eThinkingCap.com
DATE : Sat Nov 20 12:46:41 2004
Hi,
This is the first time I have made a function call like this, with a
pointer to a pointer -
-(BOOL)isWordInQuestion: (NSString *)word location: (NSString
**)location
{
NSRange r = NSMakeRange(0,0);
NSMutableString *ms = [NSMutableString string];
[ms appendString: [self stringFromRTFDData: [self questionBody]]];
[ms appendString: [self stringFromRTFDData: [self optionOne]]];
[ms appendString: [self stringFromRTFDData: [self optionTwo]]];
[ms appendString: [self stringFromRTFDData: [self optionThree]]];
[ms appendString: [self stringFromRTFDData: [self optionFour]]];
NS_DURING
r = [ms rangeOfString: word];
NS_HANDLER
if ([[localException name] isEqualToString:
NSInvalidArgumentException] ||
[[localException name] isEqualToString: NSRangeException])
{
return NO;
}
NS_ENDHANDLER
if(r.location > 0 && r.length > 0)
{
NSMutableString *s = [NSMutableString string];
[s appendString: [[self test]testName]];
[s appendString: @", "];
[s appendString: [self getQuestionNameAndNumber]];
*location = [s copy];
return YES;
}
else return NO;
}
And then another object iterates through all of the above objects and
calls the above function like so -
- (IBAction)findThisWord:(id)sender
{
NSString *word = [findWordTextField stringValue];
if(![word isEqualToString: @""])
{
for(i=0;i<[allQuestions count]; i++)
{
Question *q = [allQuestions objectAtIndex: i];
BOOL isIn;
NSString *loc =nil;
isIn = [q isWordInQuestion: word location: &loc];
if(loc)NSLog(@"%@", loc);
[loc release];
}
}
}
The big questions is - am I releasing properly, is there any leaking? I
have tested, not thoroughly, but still I am concerned. I am not
throwing and memory erros, but... How does one release, retain, copy,
when using a point to a pointer in Foundation and Objective C?
Craig Bakalian
www.eThinkingCap.com
| Related mails | Author | Date |
|---|---|---|
| Craig Bakalian | Nov 20, 12:46 | |
| Jim Correia | Nov 20, 16:23 |






Cocoa mail archive

