0

I am having trouble removing objects from nsmutable array. Here it is.

NSURL *url = [NSURL URLWithString:@"http://www.lockerz.com/dailies"]];
NSData *datadata = [NSData dataWithContentsOfURL:url];  
NSString *removeForArray = [[NSString alloc] initWithData:datadata encoding:NSASCIIStringEncoding];
NSArray *theArray = [removeForArray componentsSeparatedByString:@" "];  
NSMutableArray *deArray = [[NSMutableArray array] initWithArray:theArray];
[deArray removeObjectsInRange:NSMakeRange(0, 40)];  
NSLog(@"%@", deArray);
2
  • It crashes on me and says the following: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[__NSArrayM initWithCapacity:]!' *** Call stack at first throw: Commented Jul 18, 2010 at 19:00
  • 1
    Michael Amici: You seem to have confused alloc (which returns a blank object you own which you then need to initialize) with array (which returns an initialized empty array object you don't own). See Georg Fritzsche's answer for one solution. Commented Jul 18, 2010 at 20:38

1 Answer 1

3

+[NSMutableArray array] already returns an initialized array. Don't use an initializer method on that, they are used on new instances that you allocd.

In this case you can either

  • alloc/init an instance
  • use -mutableCopy
  • use a suitable convenience constructor

The three following lines are equivalent:

NSMutableArray *a = [[theArray mutableCopy] autorelease];
NSMutableArray *b = [NSMutableArray arrayWithArray:theArray];
NSMutableArray *c = [[[NSMutableArray alloc] initWithArray:theArray] autorelease];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.