Changing Pointers Dynamically and Build Warnings
Changing Pointers Dynamically and Build Warnings
- Subject: Changing Pointers Dynamically and Build Warnings
- From: Simone Manganelli <email@hidden>
- Date: Sun, 26 Jan 2003 02:27:44 -0800
I've got a few questions that may seem simple (I'm still learning, so
please forgive me if it's a simple fix):
1) Often times in my code, I have sections that are reused often, but
certain parts of the code cannot be made into general code. For
example, I have a routine that changes the contents of a table view by
filtering the entries based on a string that the user inputs (similar
to the iTunes search text field). The thing is, I have two different
windows I want to implement this feature in, but they need to be
implemented in slightly different ways -- I was hoping to make a
general section of code and only have parts of it be specific to the
two different windows in order to make it more manageable.
However, the problem is this: this routine changes what the table
view's data source points to (e.g.: the table view's data source points
to one array, but this routine temporarily changes the pointer to point
to a different array, even though the table view is using the same
pointer). I don't see how to make this part of the code generalized
(maybe I haven't learned something yet. Here is a sample of the code:
NSEnumerator *e = [userArray objectEnumerator];
NSString *processNameString;
NSScanner *aScanner;
id object;
if ( [searchString length] == 0 ) {
userArrayActiveSet = userArray;
tableViewAppsSortNumber--;
[self tableView:tableViewApps
didClickTableColumn:tableViewAppsSortingColumn];
return;
}
NSMutableArray *userArraySubset = [[NSMutableArray alloc]
init];
while ( object = [e nextObject] ) {
processNameString = [[object processName]
lowercaseString];
aScanner = [[NSScanner alloc]
initWithString:processNameString];
[aScanner setCaseSensitive:NO];
[aScanner scanUpToString:searchString intoString:nil];
if ( [aScanner scanString:searchString intoString:nil] )
[userArraySubset addObject:object];
[aScanner release];
}
*** userArrayActiveSet = userArraySubset;
tableViewAppsSortNumber--;
[self tableView:tableViewApps
didClickTableColumn:tableViewAppsSortingColumn];
[userArraySubset release];
The table view uses "userArrayActiveSet" as its dataSource. However,
if I generalized this code to use a general pointer (say
"pointerActiveSet" instead of "userArrayActiveSet" and "pointerSubset"
instead of "userArraySubset" at the starred line), the pointer
"pointerActiveSet" would get changed, but the table view's dataSource
wouldn't since it's still using "userArrayActiveSet", which doesn't get
changed.
If it's clear what I'm trying to do, can anybody help me find a way to
do this?
2) Often in my code I'm trying to communicate between classes, and I
instantiate the class via Interface Builder and connect them via
outlets. Then I can just call routines from the other classes by using
the outlet. However, Project Builder issues warnings that the class
does not respond to the subroutines that I want to call -- when I
actually run the program, it works as I think it should, and so the
warning does not apply. I would like to get rid of the warnings
anyway, though... how would I do that?
Thanks in advance for any help on either question.
-- Simone Manganelli
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.