Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2010, 09:59 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
racharambola5 is on a distinguished road
Default problem with containsObject in NSMutableArray

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..


Code:
-(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:@","];

				
				//	str = [first_name stringByAppendingString:@" "];
				//	str = [str stringByAppendingString:last_name];
			}
			[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;
	
}
racharambola5 is offline   Reply With Quote
Old 08-23-2010, 12:01 PM   #2 (permalink)
Registered Member
 
screwtape's Avatar
 
Join Date: Jul 2010
Location: Nottingham
Posts: 54
screwtape is on a distinguished road
Send a message via Skype™ to screwtape
Default

I'm afraid I just can't figure out what you're trying to do here.

You are adding a name to the searchContacts dictionary, then testing name against it, and if so, you are setting the return value to be a new dictionary with that name.

Couldn't you just compare name and searchContactName? If you're trying to return a dictionary of sugar_ids and constact names, you'll fail, as you're overwriting searchSugarId dictionary each time you add a name.
screwtape is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nsarray, nsmutablearray, objective c

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 341
5 members and 336 guests
freewind, HemiMG, lendo, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:55 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0