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

View Single Post
Old 11-11-2009, 02:19 AM   #14 (permalink)
XCHG
Registered Member
 
Join Date: Nov 2008
Posts: 98
XCHG is on a distinguished road
Default

Quote:
Originally Posted by AndrewSpeaksOut View Post
Here's what I did to remove null items from an NSMutableArray:

Code:
for (int i=0; i<[components count]; i++) {
if ([components objectAtIndex:i] == [NSString stringWithFormat:@""]) {
NSLog(@"nil found");
} else {
[muta addObject:[components objectAtIndex:i]];
}
}
Thanks for the help guys!
Hi,

Remember that you can not use == to see if a string is empty. You also can not insert nil/null into an array as it will raise an exception and the program will crash.

So what you can do is something like this:

Code:
NSMutableArray *MyArray = [[NSMutableArray alloc] init];
[MyArray addObject:@"One"];
[MyArray addObject:@""];
[MyArray addObject:@"Three"];

int Counter = 0;
for (Counter = 0; Counter < [MyArray count]; Counter++){
  NSString *ThisString = (NSString*) [MyArray objectAtIndex:Counter];
  if ([ThisString length] == 0){
    [MyArray removeObjectAtIndex:Counter];
    Counter = -1;
    continue;
  }
}
[MyArray release];
MyArray = nil;
I haven't written the above code in XCode. I just wrote it here so it might have some syntax errors but I think you get the idea. Make sure you use [NSString length] instead of what you did. Best of luck.
__________________
UK Flights
Latest UK Flight information right in your iPhone/iPod Touch. All major UK Airports are available in this brilliant iPhone Application. Download from the iTunes Store.

GuitarMonster: Overdrive
A guitar plugged to an overdrive effect, right in your pocket. Download from the iTunes Store.
XCHG is offline   Reply With Quote
 

» Advertisements
» Online Users: 560
19 members and 541 guests
.Snipe, cclark, cdbeshore, chrisfromnz, Domele, gordo26, iGamesDev, jon01, minglei, ndhieuvn212, nguyenhieu129, Rudy, SuperDietGenius, Techgirl-52, tjfallon, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,319
Threads: 93,988
Posts: 402,410
Top Poster: BrianSlick (7,978)
Welcome to our newest member, st02197
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:44 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.