How to push a JSQMessagesViewController correctly - ios

I have a Swift project and am trying to use JSQMessagesViewController within it. I have used cocoapods to install the framework and am importing it using a swift import statement.
import JSQMessagesViewController
Up to this point there are no errors and everything compiles without warning. However when I try to push a new instance onto a navigation controller the app crashes.
func openConversation(userId: Int) {
let messageViewController = JSQMessagesViewController();
self.navigationController?.pushViewController(messageViewController, animated: true)
}
The second line of the method causes the crash and the error message is.
2015-08-03 21:44:17.229 [4856:64097] *** Assertion failure in -[JSQMessagesViewController viewWillAppear:], /[my file path]/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.m:223
2015-08-03 21:44:17.232 [4856:64097] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: self.senderId != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00000001067e3c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108590bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001067e3aca +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000106ec298f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 JSQMessagesViewController 0x00000001060e9055 -[JSQMessagesViewController viewWillAppear:] + 277
5 UIKit 0x00000001073f8f61 -[UIViewController _setViewAppearState:isAnimating:] + 487
6 UIKit 0x000000010741a355 -[UINavigationController _startCustomTransition:] + 887
7 UIKit 0x000000010742637f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
8 UIKit 0x0000000107426ece -[UINavigationController __viewWillLayoutSubviews] + 43
9 UIKit 0x00000001075716d5 -[UILayoutContainerView layoutSubviews] + 202
10 UIKit 0x00000001073449eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
11 QuartzCore 0x0000000108f5ded2 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x0000000108f526e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000108f52556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000108ebe86e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000108ebfa22 _ZN2CA11Transaction6commitEv + 462
16 QuartzCore 0x0000000108ec00d3 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17 CoreFoundation 0x0000000106716ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x0000000106716c00 __CFRunLoopDoObservers + 368
19 CoreFoundation 0x000000010670ca33 __CFRunLoopRun + 1123
20 CoreFoundation 0x000000010670c366 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x000000010b148a3e GSEventRunModal + 161
22 UIKit 0x00000001072c48c0 UIApplicationMain + 1282
23 Startana 0x0000000105fa2807 main + 135
24 libdyld.dylib 0x0000000109306145 start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
After searching online I cant seem to find any information about what causes this issue.

I’m glad to hear it solved your issue!
The JSQMessagesViewController have two asset parameters, the senderId and the senderDisplayName.
So you must set your senderId and display name.

In your current controller which is inherited by JSQMessagesViewController
you will need to do couple of things first add setup function
func setup() {
self.senderId = "1234"
self.senderDisplayName = "TEST"
}
and latter invoke that function from
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.setup()
}

Related

Nasty Segue Error Message While Using Swift

I am relatively new to Swift and iOS in general. When I create a segue from a button to another view, I get a nasty error message (below). Can someone help me decipher this?
2016-04-17 16:25:49.133 FoodPin[9322:676896] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-u9a-Ka-ctP" from storyboard "Main", but didn't get a UITableView.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102d58d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104afcdeb objc_exception_throw + 48
2 CoreFoundation 0x0000000102d58cbd +[NSException raise:format:] + 205
3 UIKit 0x000000010396e4e2 -[UITableViewController loadView] + 638
4 UIKit 0x000000010371b560 -[UIViewController loadViewIfRequired] + 138
5 UIKit 0x000000010372193b -[UIViewController __viewWillAppear:] + 120
6 UIKit 0x0000000103751750 -[UINavigationController _startCustomTransition:] + 1203
7 UIKit 0x0000000103761b9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
8 UIKit 0x0000000103762d0b -[UINavigationController __viewWillLayoutSubviews] + 57
9 UIKit 0x0000000103911503 -[UILayoutContainerView layoutSubviews] + 248
10 UIKit 0x000000010363b980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
11 QuartzCore 0x0000000108006c00 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x0000000107ffb08e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
13 QuartzCore 0x0000000107ffaf0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000107fef3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
15 QuartzCore 0x000000010801d086 _ZN2CA11Transaction6commitEv + 486
16 QuartzCore 0x000000010801d7f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
17 CoreFoundation 0x0000000102c7dc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x0000000102c7dba7 __CFRunLoopDoObservers + 391
19 CoreFoundation 0x0000000102c737fb __CFRunLoopRun + 1147
20 CoreFoundation 0x0000000102c730f8 CFRunLoopRunSpecific + 488
21 GraphicsServices 0x00000001073eead2 GSEventRunModal + 161
22 UIKit 0x0000000103580f09 UIApplicationMain + 171
23 FoodPin 0x0000000102b589f2 main + 114
24 libdyld.dylib 0x00000001055c092d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

UitableView working fine on iOS8.4 (Xcode 6.4) but crashes on iOS9.1(Xcode 7.1.1)

The UITableView works fine when I am trying to use it through Xcode6.4, but when I'm trying it through Xcode 7.1.1 it crashes. I guess it's because of the iOS versions. I am attaching the crash log. Kindly suggest what the best way to fix it is. I am quite sure that:
1) Datasource and Delegates are working fine.
2) Numberofrows and heightOfRow methods are also getting called, but it crashes before the cellForRowAtIndexPath gets called.
Here is the log:
2016-02-05 15:34:27.400 Autograph24[3720:87023] * Assertion failure
in -[UITableViewRowData _assertValidIndexPath:allowEmptySection:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableViewRowData.m:2310
2016-02-05 15:34:27.506 Autograph24[3720:87023] * Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'Invalid indexPath'
*** First throw call stack: ( 0 CoreFoundation 0x00000001075c9f45 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000107956deb objc_exception_throw + 48 2 CoreFoundation
0x00000001075c9daa +[NSException raise:format:arguments:] + 106 3
Foundation 0x0000000106e9b5ee
-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4
UIKit 0x0000000108d11412
-[UITableViewRowData _assertValidIndexPath:allowEmptySection:] + 963 5 UIKit 0x0000000108d11465
-[UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:scrollPosition:]
+ 55 6 UIKit 0x0000000108af50c6 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 2510 7 UIKit 0x0000000108af59b9
-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 39 8 Autograph24 0x0000000106b1b2ad
-[DashboardVC scrollToToday] + 685 9 Autograph24 0x0000000106b20289 -[DashboardVC changeCalendarStyle] + 313 10
Autograph24 0x0000000106b20144 -[DashboardVC
resizeScreenForPortrait] + 788 11 Autograph24
0x0000000106b1f6a0 -[DashboardVC rotateScreen] + 176 12 Autograph24
0x0000000106b15e76 -[DashboardVC viewDidLoad] + 166 13 UIKit
0x0000000108b49cc4 -[UIViewController loadViewIfRequired] + 1198 14
UIKit 0x0000000108b4fc7b
-[UIViewController __viewWillAppear:] + 120 15 UIKit 0x0000000108b7fa37 -[UINavigationController _startCustomTransition:] +
1203 16 UIKit 0x0000000108b8fcdb
-[UINavigationController _startDeferredTransitionIfNeeded:] + 712 17 UIKit 0x0000000108b90cea
-[UINavigationController __viewWillLayoutSubviews] + 57 18 UIKit 0x0000000108d36c85 -[UILayoutContainerView layoutSubviews] + 248 19
UIKit 0x0000000108a6be40
-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710 20 QuartzCore 0x000000010736359a -[CALayer
layoutSublayers] + 146 21 QuartzCore
0x0000000107357e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE +
366 22 QuartzCore 0x0000000107357cee
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 23 QuartzCore 0x000000010734c475
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 24 QuartzCore 0x0000000107379c0a
_ZN2CA11Transaction6commitEv + 486 25 QuartzCore 0x000000010737a37c
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 26 CoreFoundation 0x00000001074f5947
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 27 CoreFoundation 0x00000001074f58b7
__CFRunLoopDoObservers + 391 28 CoreFoundation 0x00000001074eb50b __CFRunLoopRun + 1147 29 CoreFoundation
0x00000001074eae08 CFRunLoopRunSpecific + 488 30 GraphicsServices
0x000000010b1b5ad2 GSEventRunModal + 161 31 UIKit
0x00000001089b730d UIApplicationMain + 171 32 Autograph24
0x0000000106b15d9f main + 111 33 libdyld.dylib
0x000000010aac192d start + 1 34 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException
You have an invalid indexpath. That means that either the section or the row or both is not right. If you have a table with 2 sections and 2 rows per section then indexpath 0-3 is invalid, because section 0 does not provide a row 3. Similarly, indexpath 2-1 would be invalid, because section 2 does not exist (only 0 and 1).
As for how to fix this, first double check if all required methods are called and your data is correctly initialised. Then sprinkle breakpoints around your class. Mainly where you use any kind of indexpath, and see where it tries to read from outside your data.
Learn to read crash logs. In most cases and certainly in this case, they contain all the relevant information:
2016-02-05 15:34:27.400 Autograph24[3720:87023] * Assertion failure in -[UITableViewRowData _assertValidIndexPath:allowEmptySection:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableViewRowData.m:2310
2016-02-05 15:34:27.506 Autograph24[3720:87023] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid indexPath'
It clearly says: reason: 'Invalid indexPath'
So first hint: an invalid index path (which is a well known thing if you work with UITableViews) was involved.
Next follows the stack trace where the error ocurred. The first few stack locations are within Apple's code. Usually skip them. But occasionally, they contain interesting hints. Here a function assertValidIndexPath:allowEmptySection:. That again shows that the index path is the problem.
*** First throw call stack: (
0 CoreFoundation 0x00000001075c9f45 exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107956deb objc_exception_throw + 48
2 CoreFoundation 0x00000001075c9daa +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000106e9b5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 UIKit 0x0000000108d11412 -[UITableViewRowData _assertValidIndexPath:allowEmptySection:] + 963
5 UIKit 0x0000000108d11465 -[UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:scrollPosition:] + 55
6 UIKit 0x0000000108af50c6 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 2510
7 UIKit 0x0000000108af59b9 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 39
Here your code follows. Look at the line above and below. It says that your function [DashboardVC scrollToToday] has called the function [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]. This is where the error was triggered in your code.
8 Autograph24 0x0000000106b1b2ad -[DashboardVC scrollToToday] + 685
9 Autograph24 0x0000000106b20289 -[DashboardVC changeCalendarStyle] + 313
10 Autograph24 0x0000000106b20144 -[DashboardVC resizeScreenForPortrait] + 788
11 Autograph24 0x0000000106b1f6a0 -[DashboardVC rotateScreen] + 176
12 Autograph24 0x0000000106b15e76 -[DashboardVC viewDidLoad] + 166
This is the next interesting location. Here Apple's UIKit called your [DashboardVC viewDidLoad]. So that gives a lot of context. It happend early during the construction of you view in the viewDidLoad phase.
13 UIKit 0x0000000108b49cc4 -[UIViewController loadViewIfRequired] + 1198
14 UIKit 0x0000000108b4fc7b -[UIViewController __viewWillAppear:] + 120
15 UIKit 0x0000000108b7fa37 -[UINavigationController _startCustomTransition:] + 1203
16 UIKit 0x0000000108b8fcdb -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
17 UIKit 0x0000000108b90cea -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x0000000108d36c85 -[UILayoutContainerView layoutSubviews] + 248
19 UIKit 0x0000000108a6be40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
20 QuartzCore 0x000000010736359a -[CALayer layoutSublayers] + 146
21 QuartzCore 0x0000000107357e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
22 QuartzCore 0x0000000107357cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
23 QuartzCore 0x000000010734c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
24 QuartzCore 0x0000000107379c0a _ZN2CA11Transaction6commitEv + 486
25 QuartzCore 0x000000010737a37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
26 CoreFoundation 0x00000001074f5947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
27 CoreFoundation 0x00000001074f58b7 __CFRunLoopDoObservers + 391
28 CoreFoundation 0x00000001074eb50b __CFRunLoopRun + 1147
29 CoreFoundation 0x00000001074eae08 CFRunLoopRunSpecific + 488
30 GraphicsServices 0x000000010b1b5ad2 GSEventRunModal + 161
31 UIKit 0x00000001089b730d UIApplicationMain + 171
32 Autograph24 0x0000000106b15d9f main + 111
33 libdyld.dylib 0x000000010aac192d start + 1
34 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib:
terminating with uncaught exception of type NSException
Combining this information I would conclude that you call [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] from within [DashboardVC viewDidLoad], which is bound to fail with any index path because the UITableView is not properly constructed at this time of the view controller's lifecycle.
Earlier iOS versions were more lenient here; but later versions are rather restrictive about what you can do before the view controller is fully constructed.
You will need to move your [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] call to either viewWillAppear: or even viewDidAppear:.

Invalid parameter not satisfying: messageSenderId != nil

I integrated 'XBChatModule' Library from Cocoapods into my project.
When I run the code for the first time, It crashed the app by throwing following error -[XBMessage messageHash]: unrecognized selector sent to instance and it got resolved by changing XBMessage.m file as below
XBMessage.m
- (NSUInteger)messageHash
{
return self.hash;
}
But this produces new issue saying
Assertion failure in -[ChatMessagesController collectionView:cellForItemAtIndexPath:], /Users/Neelacharya/Harshit/LIve Projects/Project/V1/Source/Project/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.m:452
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: messageSenderId != nil'
*** First throw call stack:
(
0 CoreFoundation 0x000000011161ca75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001112b1bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000011161c8da +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010edcfb6f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 CinchGaming 0x000000010d7be3c5 -[JSQMessagesViewController collectionView:cellForItemAtIndexPath:] + 693
5 CinchGaming 0x000000010d7f5f6d -[XBMessageViewController collectionView:cellForItemAtIndexPath:] + 141
6 UIKit 0x00000001102b9fab -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 244
7 UIKit 0x00000001102bb6e4 -[UICollectionView _updateVisibleCellsNow:] + 3445
8 UIKit 0x00000001102bf391 -[UICollectionView layoutSubviews] + 243
9 UIKit 0x000000010fd041c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
10 QuartzCore 0x000000010f9d2c58 -[CALayer layoutSublayers] + 150
11 QuartzCore 0x000000010f9c787e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x000000010f9c76ee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x000000010f93536e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
14 QuartzCore 0x000000010f936482 _ZN2CA11Transaction6commitEv + 390
15 QuartzCore 0x000000010f936aed _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
16 CoreFoundation 0x0000000111551507 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x0000000111551460 __CFRunLoopDoObservers + 368
18 CoreFoundation 0x0000000111547293 __CFRunLoopRun + 1123
19 CoreFoundation 0x0000000111546bc6 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000112796a58 GSEventRunModal + 161
21 UIKit 0x000000010fc8a580 UIApplicationMain + 1282
22 CinchGaming 0x000000010d67e463 main + 115
23 libdyld.dylib 0x0000000111b4e145 start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I understand the reason of crash is the member messageSenderId is nil at 452'th line of JSQMessagesViewController.m file. But I don't know why does it occur and how to get it resolved.
I also reported as issue to the authors at Github, but couldn't get response.
I would appreciate if you can help me to solve the problem.
It think the application is crashing on this line:
NSString *messageSenderId = [messageItem senderId];
NSParameterAssert(messageSenderId != nil);
When I dig into that I found that the senderIdis being set from XBMessageViewController's loadDataToTable method. The only reason I can find the value for senderId is nil is you aren't setting the values for jidStr and senderId.
You will require to set jidStr and senderId and XBMessageViewController, where jidStr is receiver and senderId is self user.
Hope this helps.
You need to register your class like [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"Cell"];

Something strange happening when assigning title to UIViewController

I am having some viewControllers each connected by segues. The rootViewController is connected to the NavigationController. Now, in one UIViewController, I am performing a segue to go to another UIViewController like this and it works:
self.performSegueWithIdentifier("toLoginTypeActivity", sender: self)
The UIViewController to which I am taken to after the segues is performed is this:
import Foundation
import UIKit
class LoginTypeActivityViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
println("I am here.")
//self.title = "Namaskar" // Here seems to be something strange.
println("I am here also.")
}
}
But, the segue does not work if I comment out self.title in the code(marked as strange). Though, all the println are working. Even, "I am here also." gets printed. But, the segues is not getting performed. It gives a runtime error.
What should be the problem and how should it be resolved? I am sure I have named the identifier correctly.
Here is the runtime error:
2014-10-13 17:21:27.878 mobilepay[29387:1382271] -[Swift._NSContiguousString set]: unrecognized selector sent to instance 0x7b6b33d0
2014-10-13 17:21:27.881 mobilepay[29387:1382271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swift._NSContiguousString set]: unrecognized selector sent to instance 0x7b6b33d0'
*** First throw call stack:
(
0 CoreFoundation 0x00bb5df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x0083fa97 objc_exception_throw + 44
2 CoreFoundation 0x00bbda75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x00b069c7 ___forwarding___ + 1047
4 CoreFoundation 0x00b0658e _CF_forwarding_prep_0 + 14
5 UIFoundation 0x067eeb91 __NSStringDrawingEngine + 29221
6 UIFoundation 0x067e784d -[NSString(NSExtendedStringDrawing) drawWithRect:options:attributes:context:] + 171
7 UIKit 0x013be151 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 6626
8 UIKit 0x013bbe30 -[UILabel drawTextInRect:] + 581
9 UIKit 0x013be256 -[UILabel drawRect:] + 98
10 UIKit 0x0123354b -[UIView(CALayerDelegate) drawLayer:inContext:] + 519
11 QuartzCore 0x01077d51 -[CALayer drawInContext:] + 118
12 QuartzCore 0x01077c87 _ZL16backing_callbackP9CGContextPv + 96
13 QuartzCore 0x00f5c7ae CABackingStoreUpdate_ + 2788
14 QuartzCore 0x01077c1f ___ZN2CA5Layer8display_Ev_block_invoke + 93
15 QuartzCore 0x010ad406 x_blame_allocations + 15
16 QuartzCore 0x01077a85 _ZN2CA5Layer8display_Ev + 1591
17 QuartzCore 0x01077cd6 -[CALayer _display] + 33
18 QuartzCore 0x01077446 _ZN2CA5Layer7displayEv + 142
19 QuartzCore 0x01077cb0 -[CALayer display] + 33
20 QuartzCore 0x0106bee6 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 322
21 QuartzCore 0x0106bf6c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
22 QuartzCore 0x00fca676 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
23 QuartzCore 0x00fcba3c _ZN2CA11Transaction6commitEv + 392
24 QuartzCore 0x00fcc108 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
25 CoreFoundation 0x00ad8fbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
26 CoreFoundation 0x00ad8f00 __CFRunLoopDoObservers + 400
27 CoreFoundation 0x00ace93a __CFRunLoopRun + 1226
28 CoreFoundation 0x00ace1ab CFRunLoopRunSpecific + 443
29 CoreFoundation 0x00acdfdb CFRunLoopRunInMode + 123
30 GraphicsServices 0x0317124f GSEventRunModal + 192
31 GraphicsServices 0x0317108c GSEventRun + 104
32 UIKit 0x011a8e16 UIApplicationMain + 1526
33 mobilepay 0x001410de top_level_code + 78
34 mobilepay 0x0014111b main + 43
35 libdyld.dylib 0x03ad7ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Note that assigning to the self.title works in the other ViewControllers though.
Edit:
Here is the updated code.
class LoginTypeActivityViewController: UIViewController{
var delegate = UIApplication.sharedApplication().delegate as AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
println("viewDidLoad self.title = \(self.title)")
println("viewDidLoad self.navigationItem.title = \(self.navigationItem.title)")
}
override func viewWillAppear(animated: Bool) {
println("viewWillAppear self.title = \(self.title)")
println("viewWillAppear self.navigationItem.title = \(self.navigationItem.title)")
}
override func viewDidAppear(animated: Bool) {
println("viewDidAppear self.title = \(self.title)")
println("viewDidAppear self.navigationItem.title = \(self.navigationItem.title)")
self.navigationItem.title = "Koshish"
println("printing in viewDidAppear after setting self.navigatioItem.title = \(self.navigationItem.title)")
}
}
And here is the output:
viewDidLoad self.title = nil
viewDidLoad self.navigationItem.title = nil
viewWillAppear self.title = nil
viewWillAppear self.navigationItem.title = nil
viewDidAppear self.title = nil
viewDidAppear self.navigationItem.title = nil
printing in viewDidAppear after setting self.navigatioItem.title = Optional("Koshish")
2014-10-14 12:46:48.931 mobilepay[34547:1593230] -[Swift._NSContiguousString set]: unrecognized selector sent to instance 0x7a162090
2014-10-14 12:46:48.933 mobilepay[34547:1593230] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swift._NSContiguousString set]: unrecognized selector sent to instance 0x7a162090'
*** First throw call stack:
(
0 CoreFoundation 0x00bd3df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x0085da97 objc_exception_throw + 44
2 CoreFoundation 0x00bdba75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x00b249c7 ___forwarding___ + 1047
4 CoreFoundation 0x00b2458e _CF_forwarding_prep_0 + 14
5 UIFoundation 0x0680cb91 __NSStringDrawingEngine + 29221
6 UIFoundation 0x0680584d -[NSString(NSExtendedStringDrawing) drawWithRect:options:attributes:context:] + 171
7 UIKit 0x013dc151 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 6626
8 UIKit 0x013d9e30 -[UILabel drawTextInRect:] + 581
9 UIKit 0x013dc256 -[UILabel drawRect:] + 98
10 UIKit 0x0125154b -[UIView(CALayerDelegate) drawLayer:inContext:] + 519
11 QuartzCore 0x01095d51 -[CALayer drawInContext:] + 118
12 QuartzCore 0x01095c87 _ZL16backing_callbackP9CGContextPv + 96
13 QuartzCore 0x00f7a7ae CABackingStoreUpdate_ + 2788
14 QuartzCore 0x01095c1f ___ZN2CA5Layer8display_Ev_block_invoke + 93
15 QuartzCore 0x010cb406 x_blame_allocations + 15
16 QuartzCore 0x01095a85 _ZN2CA5Layer8display_Ev + 1591
17 QuartzCore 0x01095cd6 -[CALayer _display] + 33
18 QuartzCore 0x01095446 _ZN2CA5Layer7displayEv + 142
19 QuartzCore 0x01095cb0 -[CALayer display] + 33
20 QuartzCore 0x01089ee6 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 322
21 QuartzCore 0x01089f6c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
22 QuartzCore 0x00fe8676 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
23 QuartzCore 0x00fe9a3c _ZN2CA11Transaction6commitEv + 392
24 QuartzCore 0x00fea108 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
25 CoreFoundation 0x00af6fbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
26 CoreFoundation 0x00af6f00 __CFRunLoopDoObservers + 400
27 CoreFoundation 0x00aec93a __CFRunLoopRun + 1226
28 CoreFoundation 0x00aec1ab CFRunLoopRunSpecific + 443
29 CoreFoundation 0x00aebfdb CFRunLoopRunInMode + 123
30 GraphicsServices 0x0318f24f GSEventRunModal + 192
31 GraphicsServices 0x0318f08c GSEventRun + 104
32 UIKit 0x011c6e16 UIApplicationMain + 1526
33 mobilepay 0x00160f5e top_level_code + 78
34 mobilepay 0x00160f9b main + 43
35 libdyld.dylib 0x03af5ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Solved
I finally found the problem in my code:
In my didFinishLaunchingWithOptions, I was doing this:
var navigationBarAppearance = UINavigationBar.appearance()
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
navigationBarAppearance.tintColor = UIColor(rgba: "#000000", alpha: 1.0)
navigationBarAppearance.barTintColor = UIColor(rgba: "#000000", alpha: 1.0)
navigationBarAppearance.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Arial-BoldMT", size: 20.0), NSForegroundColorAttributeName: "#000000", alpha: 1.0)]
As you can see, in NSForegroundColorAttributeName, I was just setting the string and not calling the UIColor function with it.
I feel Swift should have given me some hint that I am not calling NSForegroundColorAttribute with the correct value.
I cannot give you the answer, but have suggestions on how you can solve it. Somehow the title property of your UINavigationItem is been set to some object not a NSString.
So where you have your "//self.title" line, log the value of title, the value of your class' UINavigationItem title, and if either is not nil, then log the class. My guess its somehow been set to a number not a string, but it may just be garbage or something released. Or, your storyboard file could have become corrupted.
EDIT: So something is really weird here. Other ideas:
if this segue is triggered before viewDidLoad by the presenting view, odd things might happen.
implement 'override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)' in the calling class, then verify you are on the main thread
use the debugger, add an exception breakpoint, and when you get the crash verify the crash is on Thread 0. Also, poke around - there is an object that doesn't respond to a selector, you have its address, so do a 'po 0x.......' in the debugger and see what it is.
failing that, you'll need to spend some time and attempt to create a demo project modeled after your real one, that has the same problem. If you can do that, you can upload it to a public site like Dropbox, update your question, and people like me will look at it (I'll at least do it). Its traditional if you get to this point to offer some bounty, I just say that so you know, but I'll look at it without one (I don't really need any more points).

NSInternalInconsistencyException - "request for layout attributes for decoration view of kind MSCollectionElementKindCurrentTimeHorizontalGridline

The application I work on is displaying a CollectionView in form of a calendar.
To simplify that we used the MSCollectionViewCalendarLayout from github.
Now it comes with multiple additional decoration views like a red line, which represents the current time in the calendar.
In our implementation there is also the possibility of filtering for different types, so the calendar not always displays the same kind/amount of cells. Unfortunately sometimes the application crashes just out of nowhere, when it should display the red timeline:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for layout attributes for decoration view of kind MSCollectionElementKindCurrentTimeHorizontalGridline in section 0 when there are only 0 sections in the collection view'
*** First throw call stack:
(
0 CoreFoundation 0x034761e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02fcb8e5 objc_exception_throw + 44
2 CoreFoundation 0x03476048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x00e2f4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x018eb290 -[UICollectionViewData layoutAttributesForDecorationViewOfKind:atIndexPath:] + 228
5 UIKit 0x018b5764 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 242
6 UIKit 0x018a8036 -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:] + 381
7 UIKit 0x018a9775 -[UICollectionView _updateVisibleCellsNow:] + 4730
8 UIKit 0x018ad65f -[UICollectionView layoutSubviews] + 265
9 UIKit 0x012d0964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
10 libobjc.A.dylib 0x02fdd82b -[NSObject performSelector:withObject:] + 70
11 QuartzCore 0x026a445a -[CALayer layoutSublayers] + 148
12 QuartzCore 0x02698244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x026980b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
14 QuartzCore 0x025fe7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
15 QuartzCore 0x025ffb85 _ZN2CA11Transaction6commitEv + 393
16 QuartzCore 0x02600258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
17 CoreFoundation 0x0343e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
18 CoreFoundation 0x0343e2bf __CFRunLoopDoObservers + 399
19 CoreFoundation 0x0341c254 __CFRunLoopRun + 1076
20 CoreFoundation 0x0341b9d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0341b7eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x049615ee GSEventRunModal + 192
23 GraphicsServices 0x0496142b GSEventRun + 104
24 UIKit 0x01261f9b UIApplicationMain + 1225
25 CariAudit 0x001036ad main + 141
26 libdyld.dylib 0x039d9701 start + 1
27 ??? 0x00000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Now I know that with this custom layout, many people get this error message when they change the underlying data of the collectionView and the solution to this is to call "invalidateLayoutCache" on the layout. The only problem is that I already have that in my code and it gets called before calling reloadData on the collectionView.
Does anyone maybe have an idea/approach for solving this kind of problem?
Thanks
After hours of searching I finally managed to find the error.
The problem was that the MSCollectionViewCalendarLayout missed to empty the Attributes-Dictionaries
currentTimeIndicatorAttributes and currentTimeHorizontalGridlineAttributes.
To fix the error all I had to do was to expand the invalidateLayoutCache method with the following:
[self.currentTimeIndicatorAttributes removeAllObjects];
[self.currentTimeHorizontalGridlineAttributes removeAllObjects];

Resources