Hi everyone, I am trying to find if there is any object in the mutable array that matches with the object I pass. Please see the function below.
The name comes from table view controller, so the row that is tapped is saved into name and passed to this function. I am trying to check whether the name in the table view controller equals to the name coming from the database. Here name refers to firstName and lastName..That's the reason I am appending those strings.
Please help me..I am confused of how to do this..if u have any better approach please let me know..thanks a lot..I think its trying to compare the memory locations of the object (not sure though) but is there any way so that it compares exactly the name that I am passing..
-(NSMutableDictionary *)getSearchContacts:(NSString *)name
{
//---retrieve rows---
NSString *qsql =[[NSString stringWithFormat:@"SELECT * FROM CONTACTS WHERE last_name LIKE '%@",[name substringToIndex:1]]stringByAppendingString:@"%' GROUP BY sugar_id ORDER BY last_name"];
NSString *sugar_id;
NSString *first_name;
NSString *last_name;
NSMutableArray *searchContacts=[[NSMutableArray alloc] init];
sqlite3_stmt *statement;
if (searchContactName == nil) {
searchContactName=[[NSString alloc]init];
}
if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
sugar_id= [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
first_name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
last_name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];
if ([first_name isEqualToString:@"(null)"]) {
last_name=[last_name stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[last_name substringToIndex:1] uppercaseString]];
searchContactName=[searchContactName stringByAppendingString:last_name];
searchContactName=[searchContactName stringByAppendingString:@":"];
searchContactName=[searchContactName stringByAppendingString:@","];
}
else {
first_name=[first_name stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[first_name substringToIndex:1] uppercaseString]];
last_name=[last_name stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[last_name substringToIndex:1] uppercaseString]];
searchContactName=[searchContactName stringByAppendingString:last_name];
searchContactName=[searchContactName stringByAppendingString:@":"];
searchContactName=[searchContactName stringByAppendingString:first_name];
searchContactName=[searchContactName stringByAppendingString:@","];
}
[searchContacts addObject:searchContactName];
//first_name = nil;
//last_name = nil;
if ([searchContacts containsObject:name]==YES) {
searchSugarId=[[NSMutableDictionary alloc]initWithObjectsAndKeys:sugar_id,searchContactName,nil];
}
}
//---deletes the compiled statement from memory---
sqlite3_finalize(statement);
}
return searchSugarId;
}
EDIT
Name: Blackmon:Valentin
Search Contact Name Barefield:Collin,Baylis:Efren,Beatty:Peter,Beckwith:Lynn,Benny:Wilma,Bermudes:Lenore,Berryhill:Gerard,Biles:Jodi,Blackmon:Valentin,Blassingame:Rose,Blume:Renae,Bonet:Claude,Bostic:Valerie,Bouldin:Renaldo,Bracewell:Brendan,Bradford:Kris,Brathwaite:Bill,Brugger:Ismael,Brumit:Julie,Buchholtz:Mathew,Bunker:Chrystal,Burch:Floyd,Burman:Sang,Butcher:Prince,Butcher:Rory,
searchContacts Barefield:Collin,Baylis:Efren,Beatty:Peter,Beckwith:Lynn,Benny:Wilma,Bermudes:Lenore,Berryhill:Gerard,Biles:Jodi,Blackmon:Valentin,Blassingame:Rose,Blume:Renae,Bonet:Claude,Bostic:Valerie,Bouldin:Renaldo,Bracewell:Brendan,Bradford:Kris,Brathwaite:Bill,Brugger:Ismael,Brumit:Julie,Buchholtz:Mathew,Bunker:Chrystal,Burch:Floyd,Burman:Sang,Butcher:Prince,Butcher:Rory,