Terminating app due to uncaught exception 'NSGenericException - iphone

I am using UIImagePickerController to load saved photo from iphone library.
but when I scroll images up or down my application crashing..
I get following error:
2011-04-21 14:26:33.357 Exchange[72452:5803] Running conversion tracker in a background thread.
2011-04-21 14:26:40.449 Exchange[72452:207] upload from gallery event here
2011-04-21 14:26:42.277 Exchange[72452:207] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6dc35a0> was mutated while being enumerated.(
"<PLImageTableSegment: 0x6937f80>",
"<null>",
"<null>",
"<null>",
"<null>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>"
)'
*** Call stack at first throw:
(
0 CoreFoundation 0x015645a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016b8313 objc_exception_throw + 44
2 CoreFoundation 0x01564069 __NSFastEnumerationMutationHandler + 377
3 CoreFoundation 0x0155d838 -[__NSArrayM dealloc] + 152
4 PhotoLibrary 0x0608d696 +[PLImageTable releaseSegmentCache] + 37
5 PhotoLibrary 0x0606cf5a -[PLPhotoLibrary dealloc] + 183
6 CoreFoundation 0x0147b04c CFRelease + 92
7 CoreFoundation 0x014a018d _CFAutoreleasePoolPop + 237
8 Foundation 0x000e33eb -[NSAutoreleasePool release] + 167
9 UIKit 0x003943ee _UIApplicationHandleEvent + 8792
10 GraphicsServices 0x01d9c992 PurpleEventCallback + 1550
11 CoreFoundation 0x01545944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12 CoreFoundation 0x014a5cf7 __CFRunLoopDoSource1 + 215
13 CoreFoundation 0x014a2f83 __CFRunLoopRun + 979
14 CoreFoundation 0x014a2840 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x014a2761 CFRunLoopRunInMode + 97
16 GraphicsServices 0x01d9b1c4 GSEventRunModal + 217
17 GraphicsServices 0x01d9b289 GSEventRun + 115
18 UIKit 0x00397c93 UIApplicationMain + 1160
19 ArmaniExchange 0x000022a4 main + 102
20 ArmaniExchange 0x00002235 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate c
alled after throwing an instance of 'NSException'
Thanks in advance.

I had the same problem. I tried he first answer here : UIImagePickerController crashes on rapid scrolling, slower than photos app
replacing
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
by
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
It works like a charm now.

Open the releaseSegmentCache method of PLImageTable. You will find code similar to this:
for (id object in array) {
// do something with object
if ([object meetsCondition:#"Foo"]) {
[array removeObject:object];
}
}
But you are not allowed to change arrays when you are enumerating them. So you have to find another solution. You could save all objects that should be removed in another array, and then delete all those when you are done enumerating. Like this for example:
NSMutableArray *objectsToDelete = [NSMutableArray array];
for (id object in array) {
// do something with object
if ([object meetsCondition:#"Foo"]) {
[objectsToDelete addObject:object];
}
}
[array removeObjectsInArray:objectsToDelete];

Look for a for loop that adds or removes objects from whatever it is iterating through. Probably in [PLImageTable releaseSegmentCache]. For example:
for (NSString *string in stringsArray) {
[stringsArray removeObject:string];
}

Related

NSarray of NSdictionaries

I am loading some values in UItableview from an array of dictionary values. I then alter the dictionary in the array by adding one more key value object as below
NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
[rowDict setObject:#"download successfull" forKey:#"downloadstatus"];
but after this when I try retrieveing value from dictionary in the array as below
NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
NSString *SelectedState = (NSString*)[rowDict objectForKey:#"downloadstatus"];
it crashes ... can any one help me out to fix this
this is the crash display on my consol
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData objectForKey:]: unrecognized selector sent to instance 0x61a8270'
*** Call stack at first throw:
(
0 CoreFoundation 0x003b0be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x015c15c2 objc_exception_throw + 47
2 CoreFoundation 0x003b26fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00322366 ___forwarding___ + 966
4 CoreFoundation 0x00321f22 _CF_forwarding_prep_0 + 50
5 SifyMyStorage 0x0003b35b -[DownloadListViewController tableView:cellForRowAtIndexPath:] + 314
6 UIKit 0x00ec67fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
7 UIKit 0x00ebc77f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
8 UIKit 0x00ed1450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
9 UIKit 0x00ec9538 -[UITableView layoutSubviews] + 242
10 QuartzCore 0x009f4451 -[CALayer layoutSublayers] + 181
11 QuartzCore 0x009f417c CALayerLayoutIfNeeded + 220
12 QuartzCore 0x009ed37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
13 QuartzCore 0x009ed0d0 _ZN2CA11Transaction6commitEv + 292
14 QuartzCore 0x00a1d7d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
15 CoreFoundation 0x00391fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
16 CoreFoundation 0x003270e7 __CFRunLoopDoObservers + 295
17 CoreFoundation 0x002efbd7 __CFRunLoopRun + 1575
18 CoreFoundation 0x002ef240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x002ef161 CFRunLoopRunInMode + 97
20 GraphicsServices 0x02ead268 GSEventRunModal + 217
21 GraphicsServices 0x02ead32d GSEventRun + 115
22 UIKit 0x00e6142e UIApplicationMain + 1160
23 SifyMyStorage 0x000020b8 main + 102
24 SifyMyStorage 0x00002049 start + 53
)
terminate called after throwing an instance of 'NSException'
See if you have allocated the object and also get the count of dictionary , if the value is being added also see if u have declared NSmutabledictionary or just NSdictionary ... a view at your class having the code would be more helpful to sort out your problem
Ok, a couple things:
-the code you posted is fine. That's not the issue. The (NSString *) cast is unnecessary, but not an issue.
-there is an issue with your NSArray tablelist. If you are really adding only NSMutableDictionary to the array, then either you are doing that wrong, or your array is going out of scope and when you think you are accessing your array, you are accessing something else in memory at that location.
-How are you retaining your reference to tablelist within the controller?
-Change your second code block to this and I'll bet you find your problem (retainCount on one of these object == 0):
NSLog(#"retain count=%d",[tableList retainCount]);
NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
NSLog(#"retain count=%d",[rowDict retainCount]);
NSString *SelectedState = [rowDict objectForKey:#"downloadstatus"];
you r not alloc the NSMutableDictionary so the NSMutableDictionary is empty and your app crashes.
NSMutableDictionary *rowDict = [[NSMutableDictionary alloc]init];
rowDict = [tableList objectAtIndex:arrayindex];
NSString *SelectedState = [rowDict objectForKey:#"downloadstatus"];
best of luck

Objective-C NSMutableArray:removeObjectsInRange

I have a NSMutableArray called rawData of size 198792. Each index contains an NSObject called DataSet. The interface for a DataSet is as follows:
#interface DataSet : NSObject {
NSNumber *rightFoot;
NSNumber *leftFoot;
}
I am trying to trim down the rawData using the following line of code:
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
where StartTime*freq-1 = 11799.
I am getting an error during runtime:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 198791 beyond bounds [0 .. 186992]'
Thank you for any help!
EDIT: stack trace
2012-02-16 17:59:31.671 fwd_analysis[8154:207] *** Terminating app due to uncaught
exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index
198791 beyond bounds [0 .. 186992]'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00db80a5 -[__NSArrayM objectAtIndex:] + 261
3 fwd_analysis 0x00002a99 -[fwd_analysisViewController startButtonPressed:] + 252
4 UIKit 0x002b24fd -[UIApplication sendAction:to:from:forEvent:] + 119
5 UIKit 0x00342799 -[UIControl sendAction:to:forEvent:] + 67
6 UIKit 0x00344c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
7 UIKit 0x003437d8 -[UIControl touchesEnded:withEvent:] + 458
8 UIKit 0x002d6ded -[UIWindow _sendTouchesForEvent:] + 567
9 UIKit 0x002b7c37 -[UIApplication sendEvent:] + 447
10 UIKit 0x002bcf2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x0171a992 PurpleEventCallback + 1550
12 CoreFoundation 0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x00d03cf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x00d00f83 __CFRunLoopRun + 979
15 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
17 GraphicsServices 0x017191c4 GSEventRunModal + 217
18 GraphicsServices 0x01719289 GSEventRun + 115
19 UIKit 0x002c0c93 UIApplicationMain + 1160
20 fwd_analysis 0x00002758 main + 102
21 fwd_analysis 0x000026e9 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
Program received signal: “SIGABRT”.
Your array can't be the size you think it is.
Look at the error message: index beyond bounds [0 .. 186992]. Therefore the size of your array is actually 186993.
I would also recommend you log the value of StartTime*freq-1 at runtime, and compare it with the length of your array.
Also, something that could cause issues here is that it's a mutable array, and you're removing stuff from it, so the length will change at runtime. This is why I recommend logging both the length and range at the point where the code breaks.
So, something like this:
NSLog(#"Length: %i",[rawData length]);
NSLog(#"Range: %i",StartTime*freq-1);
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
Update: how to add objects to another array instead of deleting from the current one.
You need to use this method to get an array which contains objects in a certain range:
- (NSArray *)subarrayWithRange:(NSRange)range
You can then add these objects into another array, for example:
// before you did this:
[rawData removeObjectsInRange:NSMakeRange(0, StartTime*freq-1)];
// to create a filtered array do:
NSArray *filtered = [rawData subarrayWithRange:NSMakeRange(0, StartTime*freq-1)];

How to understand string or array in the web service answer

I get to array value from web service. This array is 1 or more than 1-element array.If tempArra is 1 dimesional array and then If I want to transfer the data in the array to another array(garbageDatesFor01) Then I get the error
EDIT: returning to the web service responses in 2 ways
RESPONSE 1
(
(
"2011-08-03",
"2011-08-17"
)
)
OR
RESPONSE 2
2011-08-04
NSArray *garbageDatesFor01=[[NSArray alloc] initWithArray:tempArr];
2011-08-26 18:43:35.689 AOK[1846:207] -[NSCFString count]: unrecognized selector sent to instance 0x990d8f0
2011-08-26 18:43:35.691 AOK[1846:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString count]: unrecognized selector sent to instance 0x990d8f0'
*** Call stack at first throw:
(
0 CoreFoundation 0x015d25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01726313 objc_exception_throw + 44
2 CoreFoundation 0x015d40bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01543966 ___forwarding___ + 966
4 CoreFoundation 0x01543522 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x01535d87 -[NSArray initWithArray:] + 39
6 TwenteMilieu 0x0001323a -[ForgottenContainerT1 connectionDidFinishLoading:] + 3750
7 Foundation 0x00113112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
8 Foundation 0x0011306b _NSURLConnectionDidFinishLoading + 133
9 CFNetwork 0x0117148e _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
10 CFNetwork 0x0123c6e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
11 CFNetwork 0x01167c80 _ZN19URLConnectionClient13processEventsEv + 100
12 CFNetwork 0x01167acf _ZN17MultiplexerSource7performEv + 251
13 CoreFoundation 0x015b38ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
14 CoreFoundation 0x0151188b __CFRunLoopDoSources0 + 571
15 CoreFoundation 0x01510d86 __CFRunLoopRun + 470
16 CoreFoundation 0x01510840 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x01510761 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01b411c4 GSEventRunModal + 217
19 GraphicsServices 0x01b41289 GSEventRun + 115
20 UIKit 0x0037fc93 UIApplicationMain + 1160
21 TwenteMilieu 0x00002644 main + 102
22 TwenteMilieu 0x000025d5 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
The important line is :
2011-08-26 18:43:35.689 TwenteMilieu[1846:207] -[NSCFString count]: unrecognized selector sent to instance 0x990d8f0
It means you are calling count on a string. The object you think is an array is actually a string.
From looking at your code, tempArr could be either an array or a string. Try this:
if ([tempArr isKindOfClass:[NSArray class]])
{
// Handle array case
}
else if ([tempArr isKindOfClass:[NSString class]])
{
// Handle string case
}
It's probably a good idea to change the name of tempArr to something else, like tempResponse or similar.

UITable cellForRowAtIndexPath

New in iOS, here is Question:
I am using xcode 4.0.2 iso-4.3.2.
Here I have a table and I am creating one mutable array like
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
and sending that value to.Table delegate method like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
here value is coming but once I am sending dynamically value to the mainarray like
mainarray=[[NSMutableArray alloc]initWithObjects:[dataarray valueForKey:#"first_name"],nil]; or
[mainarray addobject:[dataarray valueForKey:#"first_name"]]
and sending that mainarray value to cell.textlabel.text then my program is terminating and sending this error message.
2011-05-11 10:29:10.346 picture:vide[742:207] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200
2011-05-11 10:29:10.348 picture:vide[742:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200'
*** Call stack at first throw:
(
0 CoreFoundation 0x00ddb5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2f313 objc_exception_throw + 44
2 CoreFoundation 0x00ddd0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d4c966 ___forwarding___ + 966
4 CoreFoundation 0x00d4c522 _CF_forwarding_prep_0 + 50
5 UIKit 0x003ecafc -[UILabel setText:] + 72
6 picture:vide 0x000050c9 -[VideoChatController1 tableView:cellForRowAtIndexPath:] + 376
7 UIKit 0x00340b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x003364cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x0034b8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x0034390c -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01d7ba5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d7dddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d230b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d24294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d2446d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00dbc89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d516e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d1a1d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d19840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d19761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017321c4 GSEventRunModal + 217
22 GraphicsServices 0x01732289 GSEventRun + 115
23 UIKit 0x002d9c93 UIApplicationMain + 1160
24 picture:vide 0x00002910 main + 102
25 picture:vide 0x000028a1 start + 53
)
Please, help.
Here you are getting this terminating log because
dataArray is an NSArray you can't call [dataarray valueForKey:#"first_name"] this
because this unreconised for NSArray
rether than this you may use some thing like this
[[dataarray objectAtIndex:index] valueForKey:#"first_name"]
[__NSArrayI isEqualToString:]: is the issue. You are using the isEqualToString: for an array somewhere. Check that. Its a method of NSString
Initialization of array was wrong.
Following line
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
should be corrected as
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello" , nil];
Please note the new comma between #"Hello" and nil

crashes my app [NSMutableArray1 removeAllObjects] iphone sdk

i use this code to check if any objects exist in my NSMutableArray
if yes i remove them all but it crashes although there are objects why?
if([NSMutableArray1 count]==1)
{
[poemoptionslist removeAllObjects];
}
if ([NSMutableArray1 count]==0)
{
[poemoptionslist addObject: final1];
}
CONSOLE OUTPUT
2010-10-18 03:42:13.166
app1[33398:207] * Terminating app
due to uncaught exception
'NSInternalInconsistencyException',
reason: '-[__NSCFArray
removeObjectAtIndex:]: mutating method
sent to immutable object'
* Call stack at first throw: ( 0 CoreFoundation
0x02e55b99 exceptionPreprocess + 185
1 libobjc.A.dylib
0x02fa540e objc_exception_throw + 47
2 CoreFoundation
0x02e0e238 +[NSException
raise:format:arguments:] + 136 3
CoreFoundation
0x02e0e1aa +[NSException
raise:format:] + 58 4
CoreFoundation
0x02e4d3c1 -[__NSCFArray
removeObjectAtIndex:] + 193 5
CoreFoundation
0x02dfe973 -[NSMutableArray
removeAllObjects] + 83 6
poemsoflove
0x0004dc8d -[submitpoem submitpoem:] +
18560 7 UIKit
0x003b77f8 -[UIApplication
sendAction:to:from:forEvent:] + 119 8
UIKit
0x00442de0 -[UIControl
sendAction:to:forEvent:] + 67 9
UIKit
0x00445262 -[UIControl(Internal)
_sendActionsForEvents:withEvent:] + 527 10 UIKit
0x00443e0f -[UIControl
touchesEnded:withEvent:] + 458 11
UIKit
0x003db3d0 -[UIWindow
_sendTouchesForEvent:] + 567 12 UIKit
0x003bccb4 -[UIApplication sendEvent:]
+ 447 13 UIKit 0x003c19bf _UIApplicationHandleEvent +
7672 14 GraphicsServices
0x033e6822 PurpleEventCallback + 1550
15 CoreFoundation
0x02e36ff4
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 52 16 CoreFoundation 0x02d97807 __CFRunLoopDoSource1 + 215
17 CoreFoundation
0x02d94a93 __CFRunLoopRun + 979 18
CoreFoundation
0x02d94350 CFRunLoopRunSpecific + 208
19 CoreFoundation
0x02d94271 CFRunLoopRunInMode + 97 20
GraphicsServices
0x033e500c GSEventRunModal + 217 21
GraphicsServices
0x033e50d1 GSEventRun + 115 22 UIKit
0x003c5af2 UIApplicationMain + 1160
23 poemsoflove
0x00002728 main + 102 24 poemsoflove
0x000026b9 start + 53 25 ???
0x00000001 0x0 + 1 ) terminate called
after throwing an instance of
'NSException' Program received signal:
“SIGABRT”.
Guys there is no NSArray!
I save to NSUSerdefaults like this:
if ([mutable1 count]==0)
{
[mutable1 addObject: final1];
}
NSUserDefaults *list =[NSUserDefaults standardUserDefaults];
[list setObject:mutable1 forKey:#"favorites"];
[list synchronize];
and i load data like this
NSUserDefaults *prefs1 =[NSUserDefaults standardUserDefaults];
if ( [prefs1 objectForKey:#"favorites"] != nil)
{
mutable1 = [[NSMutableArray alloc] init];
mutable1 = [prefs1 objectForKey:#"favorites"];
and i get the objects! then when it runs the removeallobjects it crashes!
mutable1 = [[NSMutableArray alloc] init];
mutable1 = [prefs1 objectForKey:#"favorites"];
Even though you've declared mutable1 to be an NSMutableArray, you are reassigning it to the object returned by your NSUserDefaults object. This object is apparently an NSArray rather than an NSMutableArray, hence the crash.
You can load your NSMutableArray with the preferences array by doing something like this:
mutable1 = [[NSMutableArray alloc] init];
[mutable1 addObjectsFromArray:[prefs1 objectForKey:#"favorites"]];
The error messages indicate that you're sending the message to an immutable array, which raises an exception. Uncaught exceptions lead to program termination.
How are you creating the array? The most common error that can lead to this is doing something like:
[mutableArray copy]
Even if the thing you're copying is mutable, the copy will be immutable. In that randomly chosen example, use mutableCopy insted.
Somewhere you have set NSMutableArray1 to an instance of NSArray, not NSMutableArray or you declared NSMutableArray1 as a property of type NSArray vs. NSMutableArray.
Also, you should follow Cocoa / Objective-C naming conventions. Namely, class names start with upper case; variables take the form myArray1 (or something more descriptive, preferably).