NSRangeException on iOS 8
I upgraded XCode 5 to 6 to test my projects out on the iPhone 6 and 6 Plus and was getting cryptic crashes on startup:
'*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]' *** First throw call stack: ( 0 CoreFoundation 0x000000010569b3f5 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000104b20bb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001055864d3 -[__NSArrayM objectAtIndex:] + 227 3 UIKit 0x00000001028164e1 _UIViewTopDownSubtreeTraversal + 193 4 UIKit 0x0000000102e43286 -[UIView(UIConstraintBasedLayout_EngineDelegate) _invalidateSystemLayoutSizeFittingSizeAtEngineDelegateLevel] + 128 5 Foundation 0x0000000103aa66df -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 915 6 Foundation 0x0000000103c2f678 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275 7 Foundation 0x0000000103a9ae3a -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220 8 UIKit 0x0000000102e40495 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474 9 Foundation 0x0000000103aa8a8e -[NSISEngine withBehaviors:performModifications:] + 155 10 UIKit 0x0000000102e4029b __57-[UIView(AdditionalLayoutSupport)
After a LOT of trial and error and trying various XIBs in various configurations, the issue occurred because I was mixing some XIBs with Auto Layout turned on, containing other UIViews (based on XIBs) with AutoLayout off.
Turning AutoLayout off for all of my XIBs solved the issue.
- iPhone 6/6+ Screen size issue
- Uploading screenshots to iTunes connect for iPhone 6 and 6+
- Can i still publish iOS apps without iPhone 6 launch images (apps that run in scale mode only)?
- How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode?
- Image resolution for new iPhone 6 and 6+, @3x support added?
- Why isn't preferredContentSize used by iPhone 6 Plus Landscape?
2 Solutions Collect From Internet About “NSRangeException on iOS 8”
Faced the same issue. Found that the problem is in button whose layer was used as mask for another button’s layer for some visual effect (
CALayer‘s mask property). Removing mask button from view hierarchy fixed the problem. I just moved it to view controller scene in storyboard.
Looks like using layer as a mask caused problem in
_UIViewTopDownSubtreeTraversal function used by autolayout. Maybe other layer manipulations for some view also can.
One solution I found is that you need to have at least 6 screens and then the app won’t crash.
Still trying to get it to work with less screens.
Turned off Auto Layout on my only XIB (LaunchScreen.xib) but that didn’t solve the problem.
- error: WatchKit apps must have a deployment target equal to iOS 8.2 (was 8.3)
- How do I append a string/number to a string ?
- CGImageRelease in Swift
- Issue when creating my first CocoaPod
- iOS 8 Custom Keyboard
- Assertion failure in UITextView _firstBaselineOffsetFromTop
- “eval” for Objective-C code
- Small video playback
- Convert CGFloat to NSNumber in Swift
- Error messages when using OpenGL ES template
- CoreTelephony Framework iOS 7
- Expanding and collapsing tableView sections iOS?
- How to get alert when when level=2 warning occurs in didReceiveMemoryWarning method in iPhone
- Accessing MKLocalSearchResponse item (swift)
- Finding IMEI number using Objective-C