[self.kvoController observe:user keyPath: #"fullName" options:NSKeyValueObservingOptionNew block:^(id observer, id object, NSDictionary *change) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *fullname = [change objectForKey:NSKeyValueChangeNewKey];
if ([fullname isKindOfClass:[NSString class]]) {
if (![weakSelf.fullnameLabel.text isEqualToString: fullname]) {
weakSelf.fullnameLabel.text = fullname;
[weakSelf.fullnameLabel sizeToFit];
}
}
});
}];
This code crashes on the 3rd line NSString *fullname = [change objectForKey:NSKeyValueChangeNewKey];
The crash log is as below:
Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00002069
0 libobjc.A.dylib 0x38449612 objc_retain + 17
1 Retro 0x0013336b __33-[ProfileHeaderView observeUser:]_block_invoke_2491 (ProfileHeaderView.m:598)
2 libdispatch.dylib 0x38922833 _dispatch_call_block_and_release + 10
3 libdispatch.dylib 0x3892281f _dispatch_client_callout + 22
4 libdispatch.dylib 0x3892949f _dispatch_main_queue_callback_4CF$VARIANT$mp + 278
5 CoreFoundation 0x2d83b8f1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
6 CoreFoundation 0x2d83a1c5 __CFRunLoopRun + 1300
7 CoreFoundation 0x2d7a4f0f CFRunLoopRunSpecific + 522
8 CoreFoundation 0x2d7a4cf3 CFRunLoopRunInMode + 106
9 GraphicsServices 0x326ca663 GSEventRunModal + 138
10 UIKit 0x300f016d UIApplicationMain + 1136
11 Retro 0x0007d253 main (main.m:16)
Any idea why it crashed because I can't replicate this on my device (the log is from crash reporter).
Related
I have following function:
-(int) getCounter:(BOOL)isIncrease {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSNumber *counter = [userDefaults valueForKey:kCounter];
int intCounter;
if (counter == nil){
intCounter = 0;
} else {
intCounter = [counter intValue];
}
if (isIncrease ){
intCounter++;
[userDefaults setObject:[NSNumber numberWithInt:intCounter] forKey:kCounter];
[userDefaults synchronize];
}
return intCounter;
}
It looks simple and clear.
However sometimes I get following Exception in Fabric:
#11. Crashed: com.my.app
0 libobjc.A.dylib 0x1866def70 objc_msgSend + 16
1 CoreFoundation 0x187c1190c -[CFPrefsPlistSource synchronize] + 96
2 CoreFoundation 0x187c36674 -[CFPrefsSearchListSource alreadylocked_requestNewData] + 88
3 CoreFoundation 0x187cd80e8 __58-[_CFXPreferences appSynchronizeWithIdentifier:container:]_block_invoke + 36
4 CoreFoundation 0x187c38ea4 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 268
5 CoreFoundation 0x187c3876c normalizeQuintuplet + 360
6 CoreFoundation 0x187c38d8c -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 104
7 CoreFoundation 0x187cd8058 -[_CFXPreferences appSynchronizeWithIdentifier:container:] + 292
8 Foundation 0x1886def90 -[NSUserDefaults(NSUserDefaults) synchronize] + 52
9 appApp 0x1004b11a4 -[MyProg getCounter:] + 4300083620
10 appApp 0x1004adb8c -[MyProg callServerWithEventName:value:withDictionary:isEvent:isNewAPI:] + 4300069772
11 appApp 0x1004ab658 __42-[MyProg sendEvent:withValues:]_block_invoke + 4300060248
12 libdispatch.dylib 0x186b1e1bc _dispatch_client_callout + 16
13 libdispatch.dylib 0x186b2af94 _dispatch_continuation_pop + 576
14 libdispatch.dylib 0x186b37634 _dispatch_source_latch_and_call + 204
15 libdispatch.dylib 0x186b20160 _dispatch_source_invoke + 820
16 libdispatch.dylib 0x186b2c210 _dispatch_queue_serial_drain + 468
17 libdispatch.dylib 0x186b219a4 _dispatch_queue_invoke + 652
18 libdispatch.dylib 0x186b2c8d8 _dispatch_queue_override_invoke + 360
19 libdispatch.dylib 0x186b2e34c _dispatch_root_queue_drain + 572
20 libdispatch.dylib 0x186b2e0ac _dispatch_worker_thread3 + 124
21 libsystem_pthread.dylib 0x186d272a0 _pthread_wqthread + 1288
22 libsystem_pthread.dylib 0x186d26d8c start_wqthread + 4
Take a look on line 9:
9 appApp 0x1004b11a4 -[MyProg getCounter:] + 4300083620
Sometimes it fails on: [NSUserDefaults(NSUserDefaults) synchronize]
and sometimes on: [NSUserDefaults(NSUserDefaults) setObject:forKey:]
Can somebody explain why I get this crash and how to avoid it?
I use UserDefaults in many places of my code but crash happen in above mentioned function.
Any suggestions?
[EDIT 1]
// in init:
mBackgroundQueue = dispatch_queue_create("com.my.app", NULL);
The root function I call getCounter:
- (void) sendEvent{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(0.1f * NSEC_PER_SEC)),
mBackgroundQueue,
^{
[self callServerWithEventName:eventName ...
withDictionary:nil
isEvent:YES
isNewAPI:YES];
}
from callServerWithEventName I call [self getCounter];
[EDIT 2]
Crash happens on setObject:forKey:]
#14. Crashed: com.my.app
0 libdispatch.dylib 0x184d397bc dispatch_group_enter + 108
1 CoreFoundation 0x185e27610 -[CFPrefsPlistSource sendFullyPreparedMessage:toConnection:settingValue:forKey:retryCount:] + 240
2 CoreFoundation 0x185e27c48 -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 388
3 CoreFoundation 0x185e26620 -[CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 864
4 CoreFoundation 0x185ee72a8 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
5 CoreFoundation 0x185e4dafc -[CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 428
6 CoreFoundation 0x185ee72a8 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
7 CoreFoundation 0x185ee7444 -[CFPrefsSource setValue:forKey:] + 60
8 CoreFoundation 0x185e505c0 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 268
9 CoreFoundation 0x185e4fe88 normalizeQuintuplet + 360
10 CoreFoundation 0x185e504a8 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 104
11 CoreFoundation 0x185eece7c -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 276
12 Foundation 0x1868a4eb8 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 68
13 ifyApp 0x1004a518c -[MyProg getCounter:] + 4300362124
14 ifyApp 0x1004a1b8c -[MyProg callServerWithEventName:value:withDictionary:isEvent:isNewAPI:] + 4300348300
15 ifyApp 0x10049f658 __42-[MyProg sendEvent:withValues:]_block_invoke + 4300338776
Thanks,
The stack trace shows your crash is occurring due to a locking conflict in synchronize as you are calling it too frequently. There is no need to call synchronize and removing the call should eliminate the issue.
You can simplify your code considerably by using integerForKey & setIntegerForKey rather than objectForKey (Or valueForKey which is incorrect) and setObjectForKey.
- (NSInteger) getCounter:(BOOL)isIncrease {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger counter = [defaults integerForKey:kCounter];
if (isIncrease) {
counter++;
[defaults setIntegerForKey:kCounter];
}
return counter;
}
The problem is that you call 'getCounter' from background queue with delay and it could be nil when you try to set 'intCounter'
To me it looks like the object was released and you are calling getCounter method anyway.
That's why it show this strange 9th line.
I'm looking into a somewhat frequent crash reported in my application's Crashlytics console.
One of the many examples I have has the following crashed thread stacktrace:
#11. Crashed: com.apple.root.default-qos
0 libobjc.A.dylib 0x22f3fa86 objc_msgSend + 5
1 Foundation 0x23ee3005 -[NSString caseInsensitiveCompare:] + 28
2 Foundation 0x23ed10bd _NSCompareObject + 28
3 Foundation 0x23ed109d _NSSortFunctionOne + 120
4 CoreFoundation 0x2373e6a3 __CFSimpleMergeSort + 114
5 CoreFoundation 0x2373e6c5 __CFSimpleMergeSort + 148
6 CoreFoundation 0x2373e6d9 __CFSimpleMergeSort + 168
7 CoreFoundation 0x2373e6c5 __CFSimpleMergeSort + 148
8 CoreFoundation 0x2373e6d9 __CFSimpleMergeSort + 168
9 CoreFoundation 0x2368ac35 CFSortIndexes + 404
10 CoreFoundation 0x2368c241 CFMergeSortArray + 176
11 Foundation 0x23ed0a9d _sortedObjectsUsingDescriptors + 456
12 Foundation 0x23f9c9fb -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 510
13 MyApp 0x6d431 __24-[MyApp refresh]_block_invoke (MyApp.m:247)
14 CoreFoundation 0x23769499 __NSArrayEnumerate + 372
15 CoreFoundation 0x236e6c3b -[NSArray enumerateObjectsWithOptions:usingBlock:] + 62
16 MyApp 0x6d17d -[MyApp refresh] (MyApp.m:263)
17 MyApp 0xa97eb __52-[MyAppRequest updateAfterNotification:]_block_invoke (MyAppRequest.m:1175)
18 libdispatch.dylib 0x23307cbf _dispatch_call_block_and_release + 10
19 libdispatch.dylib 0x233136a1 _dispatch_root_queue_drain + 1572
20 libdispatch.dylib 0x2331307b _dispatch_worker_thread3 + 94
21 libsystem_pthread.dylib 0x234a6e0d _pthread_wqthread + 1024
22 libsystem_pthread.dylib 0x234a69fc start_wqthread + 8
Other instances of the crash occur in the same app code (in the refresh method of MyApp class), but during different parts of the CoreFoundation sortedArrayUsingDescriptors method logic. For example, another crash example stacktrace has:
0 libobjc.A.dylib 0x1823cdb90 objc_msgSend + 16
1 CoreFoundation 0x182c42738 CFStringCompareWithOptionsAndLocale + 232
2 Foundation 0x183644840 _NSCompareObject + 64
3 CoreFoundation 0x182d150f4 __CFSimpleMergeSort + 196
4 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
5 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
6 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
7 CoreFoundation 0x182d1513c __CFSimpleMergeSort + 268
8 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
9 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
10 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
11 CoreFoundation 0x182c3b738 CFSortIndexes + 472
12 CoreFoundation 0x182c3cf58 CFMergeSortArray + 220
13 Foundation 0x1836440f8 _sortedObjectsUsingDescriptors + 564
14 Foundation 0x183725120 -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 564
15 MyApp 0x10006f264 __24-[MyApp refresh]_block_invoke (MyApp.m:247)
The app code in refresh is:
- (void)refresh {
NSArray *products = [self getProducts];
NSMutableArray *validProducts = [NSMutableArray array];
[products enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Product *prod = obj;
// Convert to internal native format (MyAppProduct) for business reasons...
MyAppProduct *myAppProd = [[MyAppProduct alloc] init];
myAppProd.ID = prod.id;
myAppProd.name = prod.name;
NSArray *subProds = [prod.subProds sortedArrayUsingDescriptors:#[[NSSortDescriptor sortDescriptorWithKey:#"subProds" ascending:NO]]];
NSMutableArray *validSubProds = [NSMutableArray array];
[subProds enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
SubProd *subProd = obj;
// Convert to internal native format (MyAppSubProduct) for business reasons...
MyAppSubProduct *myAppSubProd = [[MyAppSubProduct alloc] initWithSubProd:subProd];
[validSubProds addObject:myAppSubProd];
}];
myAppProd.subProds = validSubProds;
myAppProd.count = [product.count integerValue];
// Add to array
[validProducts addObject:myAppProd];
}];
// Apply array to self
_products = validProducts
}
where getProducts is:
- (NSArray*)getProducts {
NSFetchRequest *productFetchRequest = [NSFetchRequest fetchRequestWithEntityName:#"Products"];
// Filter
NSMutableArray *productsPredicates = [NSMutableArray array];
[productsPredicates addObject:[NSPredicate predicateWithFormat:#"life_uid == %#", req.lifeUid]];
[productsPredicates addObject:[NSPredicate predicateWithFormat:#"hidden == %#", #NO]];
[productFetchRequest setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:productsPredicates]];
// Sort
NSSortDescriptor *sortProductsByName = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES];
[productFetchRequest setSortDescriptors:#[sortProductsByName]];
[productFetchRequest setReturnsObjectsAsFaults:NO];
[productFetchRequest setRelationshipKeyPathsForPrefetching:#[#"subprods", #"subprods.special"]];
NSManagedObjectContext *moc = [MyAppCoreDataController sharedController].mainManagedObjectContext;
NSError *error = nil;
NSArray *products = [moc executeFetchRequest:productFetchRequest error:&error];
if (error) {
NSLog(#"Error fetching products %#", error);
}
return products;
}
And refresh is being called like so:
- (void)updateAfterNotification:(NSNotification *)notification {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[MyApp instance] refresh];
});
}
Most likely it's because you're not handling Core Data concurrency correctly. When you create a managed object context using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType, you must put all Core Data access inside a call to performBlock or performBlockAndWait. That includes fetches as well as accessing attribute values of fetched objects.
You're using dispatch_async, which is not the right way to handle concurrency with Core Data. You should switch to using performBlock or performBlockAndWait.
I got a crash from crashlytics. Probably it connected with weakSelf.
Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x000000000defe
0 libobjc.A.dylib 0x224aea44 _objc_trap()
1 libobjc.A.dylib 0x224aeaa9 _objc_inform + 70
2 libobjc.A.dylib 0x224c8413 weak_register_no_lock + 210
3 libobjc.A.dylib 0x224c8993 objc_initWeak + 130
4 GPS_______appLite 0xd77b1 -[ModuleView observeValueForKeyPath:ofObject:change:context:] (ModuleView.m:232)
5 GPS_______appLite 0xd9287 -[ModuleSpeedometerView observeValueForKeyPath:ofObject:change:context:] (ModuleSpeedometerView.m:198)
6 Foundation 0x2349aa91 NSKVONotify + 52
7 Foundation 0x23479bef NSKeyValueNotifyObserver + 286
8 Foundation 0x23479847 NSKeyValueDidChange + 346
9 Foundation 0x23466599 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 96
10 GPS_______appLite 0x12c393 -[GPSTracker private_updateCurrentStatisticsWithLocation:] (GPSTracker.mm:1887)
11 GPS_______appLite 0x12c1b9 -[GPSTracker private_addLocationToHistory:] (GPSTracker.mm:1870)
12 GPS_______appLite 0x12c6af -[GPSTracker private_processNewLocation:fromManager:] (GPSTracker.mm:1938)
13 GPS_______appLite 0x12c88b -[GPSTracker locationManager:didUpdateLocations:] (GPSTracker.mm:1953)
14 CoreLocation 0x28c5c493 (null) + 25830
15 CoreLocation 0x28c5765b (null) + 5806
16 CoreLocation 0x28c50725 (null) + 988
17 CoreFoundation 0x22cd5d91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x22cd584d __CFRunLoopDoBlocks + 216
19 CoreFoundation 0x22cd41bf __CFRunLoopRun + 1806
20 CoreFoundation 0x22c232e9 CFRunLoopRunSpecific + 520
21 CoreFoundation 0x22c230d5 CFRunLoopRunInMode + 108
22 GraphicsServices 0x24213ac9 GSEventRunModal + 160
23 UIKit 0x272e80b9 UIApplicationMain + 144
24 GPS_______appLite 0x10adc7 main (main.m:15)
25 libdispatch.dylib 0x228cb873 (Missing)
and code
//ModuleView class
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([object isKindOfClass:[GPSTracker class]])
{
__weak GPSTracker *tracker = (GPSTracker *)object;
__weak __typeof__(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
if ([keyPath isEqualToString:NSStringFromSelector(#selector(trackerMode))])
{
[weakSelf trackerStateChanged];
}
else if ([keyPath isEqualToString:NSStringFromSelector(#selector(currentStatistics))])
{
id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
if (!oldValue
|| [oldValue isKindOfClass:[NSNull class]])
{
// If statistics instance has been initialized
if (!weakSelf.shouldIgnoreUpdates)
{
[tracker.currentStatistics.time addUniqueObserver:weakSelf
forKeyPath:NSStringFromSelector(#selector(elapsed))
options:NSKeyValueObservingOptionNew];
}
}
[weakSelf trackerUpdate];
}
});
}
else if ([object isKindOfClass:[GPSTrackerTimeStatistics class]])
{
__weak __typeof__(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf timerUpdate];
});
}
}
for released version you can see crashes and line of code,
in xCode : Window-> Organizer-> Crashes
and select app and version from left panels
try "Exception Breakpoint"
Exception Breakpoint automatically add breakpoint to line has cause crash, and you can see the problem
to add Exception Breakpoint:
in xCode :
top menu -> Debug -> Breakpoints -> Create Exception Breakpoint...
and run again
I'm checking self.next_id is not null why would this line crash? I can't reproduce the issue on my test devices. I only get crash reports from Crashlytics at this line.
-(Second*)getNextSecond:(BOOL)returnSelf{
Second* retValue = nil;
if(self.next_id){
//this line !!!!
retValue = [[SecondDatabase sharedManager] getSecond:[self.next_id stringValue]];
}
if (retValue == nil && returnSelf) {
return self;
}else{
return retValue;
}
}
This is my SecondDatabase sharedManager function:
#property NSMutableDictionary* dictionary;
- (id)init {
if (self = [super init]) {
_dictionary = [#{} mutableCopy];
}
return self;
}
+ (id)sharedManager {
static SecondDatabase *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
This is my getSecond function:
-(Second*)getSecond:(NSString*)idString{
return [_dictionary objectForKey:idString];
}
Where should I be investigating? Would this crash if dictionary didn't have object for key so that it returns NULL?
My crash report:
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x000007d8
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x3acd164c realizeClass(objc_class*) + 19
1 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
2 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
3 libobjc.A.dylib 0x3acd39ab lookUpImpOrForward + 74
4 libobjc.A.dylib 0x3acd3957 _class_lookupMethodAndLoadCache3 + 34
5 libobjc.A.dylib 0x3acd88b9 _objc_msgSend_uncached + 24
6 itsmysecond-ios 0x001287c7 -[Second getNextSecond:] (Second.m:93)
7 itsmysecond-ios 0x000fd5ff -[EBParallaxViewController adjustViewsToSeconds] (EBParallaxViewController.m:181)
8 itsmysecond-ios 0x000fd21d -[EBParallaxViewController scrollViewDidEndDecelerating:] (EBParallaxViewController.m:154)
9 UIKit 0x32ed6957 -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 806
10 UIKit 0x32e0cd47 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 466
11 UIKit 0x32e0cb6b -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
12 UIKit 0x32ed621b -[UIScrollView _smoothScrollWithUpdateTime:] + 3322
13 QuartzCore 0x32a06df3 CA::Display::DisplayLinkItem::dispatch() + 98
14 QuartzCore 0x32a06b9d CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 344
15 IOMobileFramebuffer 0x3577f75d IOMobileFramebufferVsyncNotifyFunc + 104
16 IOKit 0x31209451 IODispatchCalloutFromCFMessage + 248
17 CoreFoundation 0x304ddea9 __CFMachPortPerform + 136
18 CoreFoundation 0x304e8a67 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
19 CoreFoundation 0x304e8a03 __CFRunLoopDoSource1 + 346
20 CoreFoundation 0x304e71d7 __CFRunLoopRun + 1398
21 CoreFoundation 0x30451ebf CFRunLoopRunSpecific + 522
22 CoreFoundation 0x30451ca3 CFRunLoopRunInMode + 106
23 GraphicsServices 0x35357663 GSEventRunModal + 138
24 UIKit 0x32d9e14d UIApplicationMain + 1136
25 itsmysecond-ios 0x00109707 main (main.m:14)
26 libdyld.dylib 0x3b1dbab7 start + 2
Im trying to create an infinite scroll type thing with Instagram using UITableView and AFNetworking however I get this error when I get to the bottom of the View:
CRASH :
-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object
2014-01-05 20:51:41.627 Floadt[1579:70b] STACK TRACE :
(
0 CoreFoundation 0x02b775e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027a38b6 objc_exception_throw + 44
2 CoreFoundation 0x02b773bb +[NSException raise:format:] + 139
3 CoreFoundation 0x02bfe365 -[__NSCFArray insertObject:atIndex:] + 101
4 CoreFoundation 0x02b3b2d0 -[NSMutableArray insertObjects:count:atIndex:] + 208
5 CoreFoundation 0x02b3af69 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 425
6 CoreFoundation 0x02b3ad15 -[NSMutableArray addObjectsFromArray:] + 661
7 Floadt 0x0003f5ec __42-[StreamViewController nextInstagramPage:]_block_invoke + 284
8 Floadt 0x0001edfb __64-[AFJSONRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke91 + 43
9 libdispatch.dylib 0x035247f8 _dispatch_call_block_and_release + 15
10 libdispatch.dylib 0x035394b0 _dispatch_client_callout + 14
11 libdispatch.dylib 0x0352775e _dispatch_main_queue_callback_4CF + 340
12 CoreFoundation 0x02bdca5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
13 CoreFoundation 0x02b1d6bb __CFRunLoopRun + 1963
14 CoreFoundation 0x02b1cac3 CFRunLoopRunSpecific + 467
15 CoreFoundation 0x02b1c8db CFRunLoopRunInMode + 123
16 GraphicsServices 0x0453c9e2 GSEventRunModal + 192
17 GraphicsServices 0x0453c809 GSEventRun + 104
18 UIKit 0x01936d3b UIApplicationMain + 1225
19 Floadt 0x0006646d main + 141
20 libdyld.dylib 0x037cb70d start + 1
21 ??? 0x00000001 0x0 + 1
)
Here is how I am making my code, what confuses me is the fact that all my Arrays are Mutable but it states that the mutating method was sent to an immutable object:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y == roundf(scrollView.contentSize.height-scrollView.frame.size.height)) {
NSDictionary *page = instagramResponse[#"pagination"];
NSString *nextPage = page[#"next_url"];
[[InstagramClient sharedClient] getPath:[NSString stringWithFormat:#"%#",nextPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
instagramResponse = [responseObject mutableCopy];
[instagramResponse addEntriesFromDictionary:responseObject];
[instaPics addObjectsFromArray:responseObject[#"data"]];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Failure: %#", error);
}];
}
}
before addEntriesFromDictionary the copy of Dictionarylike this
NSDictionary *copyOfDic = [[NSDictionary alloc] initWithDictionary: originalDic copyItems: YES];
if (copyOfDic ) {
[destination addEntriesFromDictionary: copyOfDic ];
[copyOfDic release];
}
or
[instaPics addObjectsFromArray:[responseObject[#"data"]mutable copy]];
or
Your #property yourarray is either initialized with an NSArray or declared copy.
because both would be lead to this error/exception message since the backing ivar would point to an (immutable) NSArray.
If you have declared your property to be of NSMutableArray type, use strong as the storage modifier instead of copy.