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 05-09-2009, 05:31 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 97
roocell is on a distinguished road
Default NSMutableArray:removeObject removing wrong object

Hi,
i have this weird problem that only occurs when I build a release target to run on the device. Everything is fine in the simulator.

I have a mutableArray and I use removeObject to remove an object from the array. Works fine everywhere but on the release target on the device this routine always removes the lastObject from the array.

Can I just submit a debug target to the app store or does it have to be the release target?
roocell is offline   Reply With Quote
Old 05-09-2009, 05:55 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by roocell View Post
Hi,
i have this weird problem that only occurs when I build a release target to run on the device. Everything is fine in the simulator.

I have a mutableArray and I use removeObject to remove an object from the array. Works fine everywhere but on the release target on the device this routine always removes the lastObject from the array.

Can I just submit a debug target to the app store or does it have to be the release target?
That shouldn't happen; if it does, it may be a symptom of a larger problem. Can you post your code you're using to remove objects? Is it in a loop?
__________________

Free Games!
smasher is offline   Reply With Quote
Old 05-09-2009, 06:39 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 97
roocell is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
That shouldn't happen; if it does, it may be a symptom of a larger problem. Can you post your code you're using to remove objects? Is it in a loop?
i purposely make sure that I dont remove it while iterating the array because that produces a crash.

Code:
-(void) updateShapeArrays:(Shape*)playedShape
{
	Shape* discard;
	Shape* shape;
	[self.ShapesPlayed addObject:playedShape];
	for (shape in self.ShapesNotPlayed)
	{
			if (playedShape.shapeInfo.id==shape.shapeInfo.id)
			{
				discard=shape;	
				//NSLog(@"remove shape %d", discard.shapeInfo.id);
			}
	}
	[self.ShapesNotPlayed removeObject:discard]; // retain the object because there are still references in the collection
	
	//NSLog(@"updateShapeArrays %d color count %d %d", playedShape.shapeInfo.color, [ShapesPlayed count], [ShapesNotPlayed count]);
}
roocell is offline   Reply With Quote
Old 05-09-2009, 06:54 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 97
roocell is on a distinguished road
Default

I have also just installed iphone OS 3.0, but i'm building with the 2.2.1 SDK.
Can I just submit my debug load to the app store? or will they reject it.
roocell is offline   Reply With Quote
Old 05-09-2009, 09:02 PM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Are is the shape passed into this method and the shape in the array the same object, or are they different objects (alloc'd in different places) but with the same id?

If they are the same object, it seems like you could just do this:

Code:
-(void) updateShapeArrays:(Shape*)playedShape
{
	[self.ShapesPlayed addObject:playedShape];
	[self.ShapesNotPlayed removeObject:playedShape];
}
I don't believe that removeObject is broken in some way in release builds, I think you have some other problem. I don't know if Apple will reject it, but I would not submit it until you've found the problem.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 05-09-2009, 09:12 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 97
roocell is on a distinguished road
Default

yes - you're right i could do that.
I had it this way because this function was copied from another that removed several objects. like this.
Code:
	NSMutableArray *discardedItems_1 = [[NSMutableArray alloc] initWithCapacity:0];
	for (cell in set)
	{
		//NSLog(@"updateDiag: testing for adjacent 
		// above
		c=[self getBoardCell:CGPointMake(cell.center.x,cell.center.y+kBlokusGridSize)];
		if (c && c->color==shape.shapeInfo.color) [discardedItems_1 addObject:cell];
		// below
		c=[self getBoardCell:CGPointMake(cell.center.x,cell.center.y-kBlokusGridSize)];
		if (c && c->color==shape.shapeInfo.color) [discardedItems_1 addObject:cell];
		// left
		c=[self getBoardCell:CGPointMake(cell.center.x-kBlokusGridSize,cell.center.y)];
		if (c && c->color==shape.shapeInfo.color) [discardedItems_1 addObject:cell];
		// right
		c=[self getBoardCell:CGPointMake(cell.center.x+kBlokusGridSize,cell.center.y)];
		if (c && c->color==shape.shapeInfo.color) [discardedItems_1 addObject:cell];
		
	}
	for (cell in discardedItems_1)
	{
		//NSLog(@"removing diag due to adjacent [%d,%d]", cell.x, cell.y);
		[set removeObject:cell];
	}
	[discardedItems_1 release];
Now I'm worried the above method (and other I have like it) will not work much in the same way the original didnt. I really appreciate the suggestion and I've made the change because it's more efficient.
But, unfortuneately, it doesnt explain the problem i was having.
roocell is offline   Reply With Quote
Old 01-04-2010, 05:09 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 126
rahul7star is on a distinguished road
Default

this is my array
self.xArray = [NSMutableArray array];
for( int i = 1; i<70; i++ )
{
[xArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"WhiteTeeGirl%d.jpg",i]]];
}


now how to delete those image already processed??
rahul7star is offline   Reply With Quote
Reply

Bookmarks

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: 314
6 members and 308 guests
givensur, guusleijsten, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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