Getting [__NSArrayM insertObject:atIndex:] tough the value is not nil - ios

I am working on UIPageViewController and I make strong for the global instance in properties below code:
UIViewController* aController = someviewController;//(I am getting the aController value)
NSArray* viewControllers = [[NSArray alloc] initWithObjects:aController, nil];
//(I am getting the viewControllers value as well).
[self.pageController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
//(I am getting crash here saying [__NSArrayM insertObject:atIndex:]: object cannot be nil').
All the instances are holding the values don't know where viewControllers is becoming nil.
please let me know
0 CoreFoundation 0x0000000105471e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010626ddeb objc_exception_throw + 48
2 CoreFoundation 0x00000001053388c5 -[__NSArrayM insertObject:atIndex:] + 901
3 0x0000000103df0b5e -[MZDashBoardViewController viewDidLoad] + 1470
4 UIKit 0x00000001071fbf98 -[UIViewController loadViewIfRequired] + 1198
5 UIKit 0x00000001071fc2e7 -[UIViewController view] + 27
6 UIKit 0x00000001077d57df -[UIPageViewController _setViewControllers:withScrollInDirection:animated:completion:] + 585
7 UIKit 0x00000001077d59fb -[UIPageViewController setViewControllers:direction:animated:completion:] + 166
8 0x0000000103decba5 -[MZMainDashViewController viewDidLoad] + 2997
9 UIKit 0x00000001071fbf98 -[UIViewController loadViewIfRequired] + 1198
10 UIKit 0x0000000107240651 -[UINavigationController _layoutViewController:] + 54
11 UIKit 0x0000000107240f26 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
12 UIKit 0x0000000107241098 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
13 UIKit 0x00000001072422f1 -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
14 UIKit 0x00000001072433af -[UINavigationController __viewWillLayoutSubviews] + 57
15 UIKit 0x00000001073e9ff7 -[UILayoutContainerView layoutSubviews] + 248
16 UIKit 0x000000010711c4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
17 QuartzCore 0x0000000106d8359a -[CALayer layoutSublayers] + 146
18 QuartzCore 0x0000000106d77e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
19 QuartzCore 0x0000000106d77cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
20 QuartzCore 0x0000000106d6c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
21 QuartzCore 0x0000000106d99c0a _ZN2CA11Transaction6commitEv + 486
22 QuartzCore 0x0000000106d9a37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
23 CoreFoundation 0x000000010539d367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x000000010539d2d7 __CFRunLoopDoObservers + 391
25 CoreFoundation 0x0000000105392f2b __CFRunLoopRun + 1147
26 CoreFoundation 0x0000000105392828 CFRunLoopRunSpecific + 488
27 GraphicsServices 0x000000010988fad2 GSEventRunModal + 161
28 UIKit 0x0000000107065610 UIApplicationMain + 171
29 0x0000000103dd2d3f main + 111
30 libdyld.dylib 0x00000001086e092d start + 1
31 ??? 0x0000000000000001 0x0 + 1

Clearly you are trying to insert an object into an immutable array, not a mutable array. Somewhere inside viewDidLoad. Remember just because a variable has type NSMutableArray* doesn't mean it is.

Related

NSMutableString stringWithString Crashes the App

This is the code i have written to display content in a label.
UILabel *content;
content = [[UILabel alloc] initWithFrame:CGRectMake(8, loaderView.frame.size.height+loaderView.frame.origin.y+15, screenBounds.size.width-16, 10)];
NSMutableString *articleContent = [NSMutableString stringWithString:[articleDictionary objectForKey:#"content"]];
The app crashes while executing the line stringWithString.I checked lot of posts related to NSMutableString crash. But i am newbie and trying to understand memory allocation.
should i check for content if nil,or is there any memory leak, what am i doing wrong.
I am using xcode 6.3, ios 8.4
the content is NSString and it has value. How to rewrite the code checking for nil
This is the exception i am getting.
0 CoreFoundation 0x0000000183c3cf48 __exceptionPreprocess + 120
1 libobjc.A.dylib 0x00000001986fff80 objc_exception_throw + 52
2 CoreFoundation 0x0000000183c3ce90 +[NSException raise:format:] + 116
3 Foundation 0x0000000184ab9680 -[NSPlaceholderMutableString initWithString:] + 108
4 Foundation 0x0000000184ab9764 +[NSString stringWithString:] + 44
5 MyProject 0x0000000100104da8 -[ArticleDetailPage renderPage] (ArticleDetailPage.m:599)
6 MyProject 0x000000010010469c -[ArticleDetailPage viewWillAppear:] (ArticleDetailPage.m:556)
7 UIKit 0x00000001891e85f4 -[UIViewController _setViewAppearState:isAnimating:] + 624
8 UIKit 0x00000001891e8368 -[UIViewController __viewWillAppear:] + 152
9 UIKit 0x0000000189381fb4 -[UINavigationController _startCustomTransition:] + 1048
10 UIKit 0x000000018928e190 -[UINavigationController _startDeferredTransitionIfNeeded:] + 684
11 UIKit 0x000000018928de6c -[UINavigationController __viewWillLayoutSubviews] + 56
12 UIKit 0x000000018928ddd4 -[UILayoutContainerView layoutSubviews] + 204
13 UIKit 0x00000001891cb7ac -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 640
14 QuartzCore 0x00000001889cab58 -[CALayer layoutSublayers] + 144
15 QuartzCore 0x00000001889c5764 CA::Layer::layout_if_needed() + 288
16 QuartzCore 0x00000001889c5624 CA::Layer::layout_and_display_if_needed() + 28
17 QuartzCore 0x00000001889c4cc0 CA::Context::commit_transaction() + 248
18 QuartzCore 0x00000001889c4a08 CA::Transaction::commit() + 508
19 UIKit 0x00000001891c19d8 _afterCACommitHandler + 176
20 CoreFoundation 0x0000000183bf3bd0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
21 CoreFoundation 0x0000000183bf1974 __CFRunLoopDoObservers + 368
22 CoreFoundation 0x0000000183bf1da4 __CFRunLoopRun + 924
23 CoreFoundation 0x0000000183b20ca0 CFRunLoopRunSpecific + 380
24 GraphicsServices 0x000000018ed5c088 GSEventRunModal + 176
25 UIKit 0x0000000189238ffc UIApplicationMain + 200
26 MyProject 0x00000001000ee7b4 main (main.m:15)
27 libdyld.dylib 0x0000000198f4e8b8 start + 0
Try this instead:
NSMutableString *articleContent = [articleDictionary[#"content"] mutableCopy];
If it's not set in the dictionary it will be nil and it avoids the potential crash in [NSMutableString stringWithString] (calling mutableCopy on nil is silently ignored).

Error with Parse integrated with Swift

When I'm trying to make a social media-like app using Parse, I get the following error when trying to go to the section to compose a "sweet". I'm trying to recreate what is in this video: (https://youtu.be/Q6kTw_cK3zY), and this is the error I am getting in the console output :
*** First throw call stack:
(
0 CoreFoundation 0x0000000105cfdc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107868bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105cfd8a9 -[NSException raise] + 9
3 Foundation 0x000000010611bb53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000105c45d50 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010687452b -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x00000001066cc718 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x00000001066ccd08 -[UIViewController loadView] + 109
8 UIKit 0x00000001066ccf79 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x00000001066cd40e -[UIViewController view] + 27
10 UIKit 0x00000001066f2297 -[UINavigationController _startCustomTransition:] + 633
11 UIKit 0x00000001066fe3bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
12 UIKit 0x00000001066fef0e -[UINavigationController __viewWillLayoutSubviews] + 43
13 UIKit 0x0000000106849715 -[UILayoutContainerView layoutSubviews] + 202
14 UIKit 0x000000010661ca2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
15 QuartzCore 0x00000001058caec2 -[CALayer layoutSublayers] + 146
16 QuartzCore 0x00000001058bf6d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x00000001058bf546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x000000010582b886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
19 QuartzCore 0x000000010582ca3a _ZN2CA11Transaction6commitEv + 462
20 UIKit 0x0000000106599626 _UIApplicationHandleEventQueue + 2140
21 CoreFoundation 0x0000000105c31431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x0000000105c272fd __CFRunLoopDoSources0 + 269
23 CoreFoundation 0x0000000105c26934 __CFRunLoopRun + 868
24 CoreFoundation 0x0000000105c26366 CFRunLoopRunSpecific + 470
25 GraphicsServices 0x0000000108c02a3e GSEventRunModal + 161
26 UIKit 0x000000010659c900 UIApplicationMain + 1282
27 switter 0x0000000104834767 main + 135
28 libdyld.dylib 0x000000010883d145 start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

iOS - Exception setting text to UILabel property

I am facing a strange issue in one of my View Controllers, Every thing works fine and loads fine but when ever i set a Value to the View i get an Exception related to layer. However i am not setting any properties to the Layer either in Interface Builder or in the Code. Below is the Log that i receive which right now makes no sense to me
-[__NSCFNumber length]: unrecognized selector sent to instance 0x923a4e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x923a4e0'
*** First throw call stack:
(
0 CoreFoundation 0x01ef31e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01bf08e5 objc_exception_throw + 44
2 CoreFoundation 0x01f90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01ee350b ___forwarding___ + 1019
4 CoreFoundation 0x01ee30ee _CF_forwarding_prep_0 + 14
5 UIKit 0x00a6d463 -[UILabel _shadow] + 45
6 UIKit 0x00a6e8c2 -[UILabel drawTextInRect:] + 70
7 UIKit 0x00a70dfc -[UILabel drawRect:] + 98
8 UIKit 0x0091f453 -[UIView(CALayerDelegate) drawLayer:inContext:] + 504
9 QuartzCore 0x00213f39 -[CALayer drawInContext:] + 123
10 QuartzCore 0x00213e6a _ZL16backing_callbackP9CGContextPv + 96
11 QuartzCore 0x001024fc CABackingStoreUpdate_ + 2656
12 QuartzCore 0x00213e02 ___ZN2CA5Layer8display_Ev_block_invoke + 93
13 QuartzCore 0x002482d7 x_blame_allocations + 15
14 QuartzCore 0x00213c6d _ZN2CA5Layer8display_Ev + 1519
15 QuartzCore 0x00213eb9 -[CALayer _display] + 33
16 QuartzCore 0x00213676 _ZN2CA5Layer7displayEv + 144
17 QuartzCore 0x00213e93 -[CALayer display] + 33
18 QuartzCore 0x00210fb7 -[CALayer displayIfNeeded] + 57
19 QuartzCore 0x002113b1 -[CALayer renderInContext:] + 192
20 QuartzCore 0x00213376 -[CALayer _renderSublayersInContext:] + 413
21 QuartzCore 0x002118bc -[CALayer renderInContext:] + 1483
22 QuartzCore 0x00213376 -[CALayer _renderSublayersInContext:] + 413
23 QuartzCore 0x002118bc -[CALayer renderInContext:] + 1483
24 QuartzCore 0x00213376 -[CALayer _renderSublayersInContext:] + 413
25 QuartzCore 0x002118bc -[CALayer renderInContext:] + 1483
26 SilverStar 0x00011fad -[UIView(ABExtras) imageInNavController:] + 525
27 SilverStar 0x00013005 -[CubeNavigationController pushViewController:animated:] + 549
28 SilverStar 0x0000c936 -[MSArticleViewController detailsbuttonTapped:] + 438
29 libobjc.A.dylib 0x01c02880 -[NSObject performSelector:withObject:withObject:] + 77
30 UIKit 0x008b23b9 -[UIApplication sendAction:to:from:forEvent:] + 108
31 UIKit 0x008b2345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
32 UIKit 0x009b3bd1 -[UIControl sendAction:to:forEvent:] + 66
33 UIKit 0x009b3fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
34 UIKit 0x009b3243 -[UIControl touchesEnded:withEvent:] + 641
35 UIKit 0x00c482e3 _UIGestureRecognizerUpdate + 7166
36 UIKit 0x008f1a5a -[UIWindow _sendGesturesForEvent:] + 1291
37 UIKit 0x008f2971 -[UIWindow sendEvent:] + 1021
38 UIKit 0x008c45f2 -[UIApplication sendEvent:] + 242
39 UIKit 0x008ae353 _UIApplicationHandleEventQueue + 11455
40 CoreFoundation 0x01e7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
41 CoreFoundation 0x01e7c10b __CFRunLoopDoSources0 + 235
42 CoreFoundation 0x01e991ae __CFRunLoopRun + 910
43 CoreFoundation 0x01e989d3 CFRunLoopRunSpecific + 467
44 CoreFoundation 0x01e987eb CFRunLoopRunInMode + 123
45 GraphicsServices 0x036c25ee GSEventRunModal + 192
46 GraphicsServices 0x036c242b GSEventRun + 104
47 UIKit 0x008b0f9b UIApplicationMain + 1225
Note: I am not sure which Code Section you might require. So, Let me know i will add in the Question here
You are passing NSNumber instead of NSString. Try this:
NSString *myString = [aNumber stringValue]; // aNumber is a NSNumber
self.label.text = myString
Hope this helps.. :)

ios fatal exception error - NSInvalidArgumentException NSInvalidArgumentException

I got crash issue from Crashlytics.
UIKit
-[UIView(Internal) _addSubview:positioned:relativeTo:]
Fatal Exception: NSInvalidArgumentException NSInvalidArgumentException
Can't add self as subview
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x2e9a0f4b __exceptionPreprocess + 130
1 libobjc.A.dylib 0x391376af objc_exception_throw + 38
2 CoreFoundation 0x2e9a0e8d -[NSException initWithCoder:]
3 UIKit 0x3111f48f -[UIView(Internal) _addSubview:positioned:relativeTo:] + 110
4 UIKit 0x3111f417 -[UIView(Hierarchy) addSubview:] + 30
5 UIKit 0x312e7c2f __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1402
6 UIKit 0x311256e5 +[UIView(Animation) performWithoutAnimation:] + 72
7 UIKit 0x312e7479 -[_UINavigationParallaxTransition animateTransition:] + 728
8 UIKit 0x312a4ba7 -[UINavigationController _startCustomTransition:] + 2614
9 UIKit 0x311c2273 -[UINavigationController _startDeferredTransitionIfNeeded:] + 418
10 UIKit 0x311c207d -[UINavigationController __viewWillLayoutSubviews] + 44
11 UIKit 0x311c2015 -[UILayoutContainerView layoutSubviews] + 184
12 UIKit 0x31113da3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
13 QuartzCore 0x30d9ac6b -[CALayer layoutSublayers] + 142
14 QuartzCore 0x30d9647b CA::Layer::layout_if_needed(CA::Transaction*) + 350
15 QuartzCore 0x30d9630d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
16 QuartzCore 0x30d95d1f CA::Context::commit_transaction(CA::Transaction*) + 230
17 QuartzCore 0x30d95b2f CA::Transaction::commit() + 314
18 QuartzCore 0x30d8f85d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
19 CoreFoundation 0x2e96c1cd
20 CoreFoundation 0x2e969b71 __CFRunLoopDoObservers + 284
21 CoreFoundation 0x2e969eb3 __CFRunLoopRun + 730
22 CoreFoundation 0x2e8d4c27 CFRunLoopRunSpecific + 522
23 CoreFoundation 0x2e8d4a0b CFRunLoopRunInMode + 106
24 GraphicsServices 0x335c8283 GSEventRunModal + 138
25 UIKit 0x31178049 UIApplicationMain + 1136
26 Tapastic 0x000764ef main (main.m:16)
27 Tapastic 0x00075bf0 start
I cannot find where this crash happened in codes. So how can I find where this crash is and fix it? Please let me know. Thanks in advance.

MKMapView unexpected crash issue

In viewDidLoad I have only 2 strings:
MKMapView *mapViewMy = [[MKMapView alloc]init];
[self.view addSubview:mapViewMy];
And the app crashed on "[self.view addSubview:mapViewMy]". I use iOS7. It crashes both on devices and simulators. When I use simulator I have crash report:
2013-11-06 13:34:15.948 MyBex JAPanel[36286:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x0216c5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01eef8b6 objc_exception_throw + 44
2 CoreFoundation 0x0211ebcc -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x0211e870 -[__NSArrayM addObject:] + 64
4 UIKit 0x01190b67 PushNextClassForSettingIMP + 358
5 UIKit 0x0118905e TaggingAppearanceObjectSetterIMP + 43
6 UIKit 0x00d6d8de -[UIViewController _setUpLayoutGuideConstraintIfNecessaryAtTop:] + 424
7 UIKit 0x00d6c1c3 -[UIViewController topLayoutGuide] + 140
8 MapKit 0x023d16a8 -[MKMapView updateLayoutGuides] + 82
9 MapKit 0x023d17e7 -[MKMapView didMoveToSuperview] + 68
10 UIKit 0x00cba636 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 472
11 UIKit 0x00cba388 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
12 UIKit 0x00cc54c1 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
13 UIKit 0x00cb89b1 -[UIView(Hierarchy) addSubview:] + 56
14 UIKit 0x01189077 TaggingAppearanceObjectSetterIMP + 68
15 MyBex JAPanel 0x0001180e -[MapViewController configureView] + 142
16 MyBex JAPanel 0x00011778 -[MapViewController viewDidLoad] + 88
17 UIKit 0x00d71318 -[UIViewController loadViewIfRequired] + 696
18 UIKit 0x00d96b15 -[UINavigationController _layoutViewController:] + 39
19 UIKit 0x00d9702b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
20 UIKit 0x00d97123 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
21 UIKit 0x00d9809c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
22 UIKit 0x00d98cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
23 UIKit 0x00ed2181 -[UILayoutContainerView layoutSubviews] + 213
24 UIKit 0x00cc8267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
25 libobjc.A.dylib 0x01f0181f -[NSObject performSelector:withObject:] + 70
26 QuartzCore 0x005c82ea -[CALayer layoutSublayers] + 148
27 QuartzCore 0x005bc0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
28 QuartzCore 0x005bbf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
29 QuartzCore 0x00523ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
30 QuartzCore 0x00524e71 _ZN2CA11Transaction6commitEv + 393
31 QuartzCore 0x005e1430 +[CATransaction flush] + 52
32 UIKit 0x00c79dc9 _afterCACommitHandler + 131
33 CoreFoundation 0x021344ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
34 CoreFoundation 0x0213441f __CFRunLoopDoObservers + 399
35 CoreFoundation 0x02112344 __CFRunLoopRun + 1076
36 CoreFoundation 0x02111ac3 CFRunLoopRunSpecific + 467
37 CoreFoundation 0x021118db CFRunLoopRunInMode + 123
38 GraphicsServices 0x027f29e2 GSEventRunModal + 192
39 GraphicsServices 0x027f2809 GSEventRun + 104
40 UIKit 0x00c5dd3b UIApplicationMain + 1225
41 MyBex JAPanel 0x0003bc0d main + 141
42 libdyld.dylib 0x03423725 start + 0
43 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I checked, both mapViewMy and self.view are not nil.
Its seems like in our viewDidLoad your object is miss referencing
Make sure you have added Framework of MapKit
Import Map Kit & Delegate in your .h file
Try this code :
MKMapView *mapViewMy = [[MKMapView alloc] initWithFrame:self.view.bounds];
mapViewMy.delegate=self;
[self.view addSubview:mapViewMy];
You need to add map kit delegates methods. :)
in .h file
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
//import MKMapkit framwork
#interface mapSampleViewController : UIViewController {
<MKMapViewDelegate>//mapview delegate
{
MKMapView *mapView;
}
in .m file
add this code in viewdidload
mapView= [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
mapView.delegate = self;
[self.view addSubview:mapView];

Resources