ReactiveCocoa Issue - ios

I'm attempting to use ReactiveCocoa in my project to handle the population of a UITableView.
When I load the data if none is available, I want to set the hidden property of tableView.backgroundView to false. Here's what I have so far:
func loadData() {
let dataSource = tableView.dataSource as! BlockedTableViewDataSource
let load = dataSource.load(currentUser) # RACSignal
load.map {
return ($0 as! [AnyObject]).count > 0
}.startWith(true).distinctUntilChanged().setKeyPath("hidden", onObject: tableView.backgroundView!)
load.subscribeError({ error in
println(error)
}, completed: {
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
})
}
This however errors out saying that I need to wait for the network request to finish. I'm using Parse to fetch the data but I'm thinking that my ReactiveCocoa code just isn't set up correctly and is causing this error. If I comment out the load.map... portion the table populates as expected.
How would one going about implementing this in the "Reactive Way"?
Update #1
Here is the load function of the dataSource
func load(user: User) -> RACSignal {
return self.getBlocks(user).doNext {
self.blocks = $0 as! [Block]
}
}
private func getBlocks(fromUser: User) -> RACSignal {
let query = Block.query()!
query.whereKey("fromUser", equalTo: fromUser)
query.includeKey("toUser")
return query.rac_findObjects()
}
Update #2
2015-04-28 08:20:02.612 ohio[90547:2154845] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This query has an outstanding network connection. You have to wait until it's done.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b840c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bc5dbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010b840b9d +[NSException raise:format:] + 205
3 ohio 0x0000000107facb1b -[PFQuery checkIfCommandIsRunning] + 77
4 ohio 0x0000000107facb71 -[PFQuery markAsRunning:] + 46
5 ohio 0x0000000107fad105 -[PFQuery _findObjectsAsync:after:] + 234
6 ohio 0x0000000107faf0a0 -[PFQuery findObjectsInBackgroundWithBlock:] + 288
7 ohio 0x0000000107d9532d _TFFE4ohioCSo7PFQuery15rac_findObjectsFS0_FT_CSo9RACSignalU_FGSQPSo13RACSubscriber__GSQCSo13RACDisposable_ + 205
8 ohio 0x0000000107d6639e _TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFo_iGSQPS____iGSQS0___ + 30
9 ohio 0x0000000107d944c1 _TPA__TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFo_iGSQPS____iGSQS0___ + 81
10 ohio 0x0000000107d663d4 _TTRXFo_iGSQPSo13RACSubscriber___iGSQCSo13RACDisposable__XFo_oGSQPS____oGSQS0___ + 36
11 ohio 0x0000000107d66418 _TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFdCb_dGSQPS____aGSQS0___ + 56
12 ohio 0x0000000107eeacca __30-[RACDynamicSignal subscribe:]_block_invoke + 74
13 ohio 0x0000000107f35b8e -[RACSubscriptionScheduler schedule:] + 478
14 ohio 0x0000000107eeab9d -[RACDynamicSignal subscribe:] + 765
15 ohio 0x0000000107f28f1d -[RACSignal(Subscription) subscribeNext:error:completed:] + 1133
16 ohio 0x0000000107f004cc __32-[RACSignal(Operations) doNext:]_block_invoke + 396
17 ohio 0x0000000107eeacca __30-[RACDynamicSignal subscribe:]_block_invoke + 74
18 ohio 0x0000000107f35b8e -[RACSubscriptionScheduler schedule:] + 478
19 ohio 0x0000000107eeab9d -[RACDynamicSignal subscribe:] + 765
20 ohio 0x0000000107f2999e -[RACSignal(Subscription) subscribeError:completed:] + 766
21 ohio 0x0000000107dc5fdb _TFC4ohio26BlockedTableViewController8loadDatafS0_FCS_4UserT_ + 3083
22 ohio 0x0000000107dc6775 _TFC4ohio26BlockedTableViewController11viewDidLoadfS0_FT_T_ + 501
23 ohio 0x0000000107dc7702 _TToFC4ohio26BlockedTableViewController11viewDidLoadfS0_FT_T_ + 34
24 UIKit 0x000000010a142210 -[UIViewController loadViewIfRequired] + 738
25 UIKit 0x000000010a14240e -[UIViewController view] + 27
26 UIKit 0x000000010a167297 -[UINavigationController _startCustomTransition:] + 633
27 UIKit 0x000000010a1733bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
28 UIKit 0x000000010a173f0e -[UINavigationController __viewWillLayoutSubviews] + 43
29 UIKit 0x000000010a2be715 -[UILayoutContainerView layoutSubviews] + 202
30 UIKit 0x000000011915093e -[UILayoutContainerViewAccessibility layoutSubviews] + 43
31 UIKit 0x000000010a091a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
32 QuartzCore 0x0000000109d12ec2 -[CALayer layoutSublayers] + 146
33 QuartzCore 0x0000000109d076d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
34 QuartzCore 0x0000000109d07546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
35 QuartzCore 0x0000000109c73886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
36 QuartzCore 0x0000000109c74a3a _ZN2CA11Transaction6commitEv + 462
37 QuartzCore 0x0000000109c750eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
38 CoreFoundation 0x000000010b773ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
39 CoreFoundation 0x000000010b773c00 __CFRunLoopDoObservers + 368
40 CoreFoundation 0x000000010b769a33 __CFRunLoopRun + 1123
41 CoreFoundation 0x000000010b769366 CFRunLoopRunSpecific + 470
42 GraphicsServices 0x000000010cfc8a3e GSEventRunModal + 161
43 UIKit 0x000000010a011900 UIApplicationMain + 1282
44 ohio 0x0000000107d86df7 main + 135
45 libdyld.dylib 0x000000010c3c1145 start + 1
46 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

The method rac_findObjects() returns a cold signal. It means that each time someone subscribes to this signal, its side effects (that is, executing the underlying network request) will be repeated. And it seems that PFQuery doesn't allow to send more than one simultaneous request, hence the error message.
In your case you are making two subscriptions for the load signal, because calling setKeyPath also creates one. So the networks request gets executed twice, which results in the error you posted.
As suggested in the linked GitHub issue, you can use RACMulticastConnection to ensure that the side effects (the network request) are executed only once, no matter how many subscribers there are. For example:
let load = dataSource.load(currentUser).publish().autoconnect()

Related

iOS 13: Searchbar crashing when cancel is hit repeatedly

I'm getting a crash when users click the cancel button repeatedly:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Nested internal _UISearchBar transitions not yet supported. This is an internal UIKit bug.'
Steps:
Launch a window with the search bar showing.
Make the search bar text field the first responder. I have the cancel button enabled, so it shows up.
Tap on the location of the cancel button a few times.
Watch the app crash.
Log:
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23b98bde __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff503b5b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23b98958 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff468697ba -[_UISearchBarVisualProviderIOS prepareForTransitionToSearchLayoutState:] + 1306
5 UIKitCore 0x00007fff46869174 -[_UISearchBarVisualProviderIOS driveTransitionToSearchLayoutState:] + 180
6 UIKitCore 0x00007fff471c046a __68-[_UISearchControllerTransplantSearchBarAnimator animateTransition:]_block_invoke.98 + 107
7 UIKitCore 0x00007fff4762a1e6 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 528
8 UIKitCore 0x00007fff4762a795 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 99
9 UIKitCore 0x00007fff471bfc15 -[_UISearchControllerTransplantSearchBarAnimator animateTransition:] + 862
10 UIKitCore 0x00007fff46b2c49e ___UIViewControllerTransitioningRunCustomTransition_block_invoke_2 + 54
11 UIKitCore 0x00007fff46c41ece +[UIInputResponderController _pinInputViewsForInputResponderController:onBehalfOfResponder:duringBlock:] + 99
12 UIKitCore 0x00007fff46b2c432 ___UIViewControllerTransitioningRunCustomTransition_block_invoke.645 + 180
13 UIKitCore 0x00007fff47628751 +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:] + 175
14 UIKitCore 0x00007fff46b2c2b8 _UIViewControllerTransitioningRunCustomTransition + 553
15 UIKitCore 0x00007fff46a0fccb __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.452 + 2632
16 UIKitCore 0x00007fff4716b85a _runAfterCACommitDeferredBlocks + 352
17 UIKitCore 0x00007fff4715c63c _cleanUpAfterCAFlushAndRunDeferredBlocks + 248
18 UIKitCore 0x00007fff4718bc6e _afterCACommitHandler + 85
19 CoreFoundation 0x00007fff23afaeb7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x00007fff23af594e __CFRunLoopDoObservers + 430
21 CoreFoundation 0x00007fff23af5fca __CFRunLoopRun + 1514
22 CoreFoundation 0x00007fff23af56b6 CFRunLoopRunSpecific + 438
23 GraphicsServices 0x00007fff3815cbb0 GSEventRunModal + 65
24 UIKitCore 0x00007fff47162a67 UIApplicationMain + 1621
25 Properly 0x000000010d3426d2 main + 80
26 libdyld.dylib 0x00007fff5123bcf5 start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Simple solution could be disable cancel button upon tapping once. And then perform the operation under it and when process gets completed you can enable it if you want.
find the below fix for this issue.
var isSeachBarAnimationCompleted: Bool = false
func didPresentSearchController(_ searchController: UISearchController) {
DispatchQueue.main.async(execute:
{
self.isSeachBarAnimationCompleted = true
searchController.searchBar.becomeFirstResponder()
})
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
{
guard self.isSeachBarAnimationCompleted else
{
return
}
self.isSeachBarAnimationCompleted = false
//Do you code here...
}
Hope this will resolve the issue.

Why calling selector of the subclass raise error, while the parent(s) certainly have it?

I'm using JSQMessageViewController for chat UI. The JSQMessageViewController implements UIScrollViewDelegate, and having scrollViewDidScroll: function.
And then I subclass JSQMessageViewController into MessagesVc. The scrollViewDidScroll: is called correctly without I even need to override it in the MessagesVc.
And then I create another subclass of JSQMessageViewController as JSQBaseViewController. I override the scrollViewDidScroll: here, and also calling super.scrollViewDidScroll: inside it. My MessagesVc now is a subclass of JSQBaseViewController instead of JSQMessageViewController.
But when I ran the app, now it raise the error: reason: '-[MyApps.MessagesVc scrollViewDidScroll:]: unrecognized selector sent to instance 0x7fe5ed00aa00'. Why is this happened? I don't think this error is supposed to happen, right?
EDIT: I tried to override scrollViewDidScroll: in MessagesVc and it still doesn't work.
Here is the circumstances of the implementation of scrollViewDidScroll: override:
import JSQMessageViewController
class JSQBaseViewController : JSQMessageViewController {
...
}
extension JSQBaseViewController {
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
super.scrollViewDidScroll(scrollView)
...
}
}
class MessagesVc : JSQBaseViewController {
...
// still no override implementation of scrollViewDidScroll here
}
Call stack:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyApps.MessagesVc scrollViewDidScroll:]: unrecognized selector sent to instance 0x7fe5ed00aa00'
*** First throw call stack:
(
0 CoreFoundation 0x00000001084f01e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000107b85031 objc_exception_throw + 48
2 CoreFoundation 0x0000000108571784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x00000001098df73b -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x00000001084725f8 ___forwarding___ + 760
5 CoreFoundation 0x0000000108472278 _CF_forwarding_prep_0 + 120
6 MyApps 0x0000000105362eb3 _T06MyApps21JSQBaseViewControllerC06scrollC9DidScrollySo08UIScrollC0CF + 131
7 MyApps 0x0000000105363e2c _T06MyApps21JSQBaseViewControllerC06scrollC9DidScrollySo08UIScrollC0CFTo + 60
8 UIKit 0x00000001097a8bcf -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 66
9 UIKit 0x000000010978eb87 -[UIScrollView setContentOffset:] + 468
10 UIKit 0x00000001097ac854 -[UIScrollView(UIScrollViewInternal) _setContentOffset:animated:animationCurve:animationAdjustsForContentOffsetDelta:animation:] + 1022
11 UIKit 0x000000010a187f35 -[UICollectionView setContentOffset:animated:] + 350
12 JSQMessagesViewController 0x0000000106f842e5 -[JSQMessagesViewController scrollToIndexPath:animated:] + 2165
13 JSQMessagesViewController 0x0000000106f83a59 -[JSQMessagesViewController scrollToBottomAnimated:] + 265
14 JSQMessagesViewController 0x0000000106f83714 -[JSQMessagesViewController finishSendingMessageAnimated:] + 660
15 JSQMessagesViewController 0x0000000106f83470 -[JSQMessagesViewController finishSendingMessage] + 48
16 MyApps 0x000000010584350b _T06MyApps10MessagesVcC13reloadDisplayyyF + 27
17 MyApps 0x0000000105843544 _T06MyApps10MessagesVcC13reloadDisplayyyFTo + 36
18 MyApps 0x000000010561f713 _T06MyApps10MessagesVcC10dataSourceSayAA9MyMessageCGSgvW + 35
19 MyApps 0x000000010561f6c9 _T06MyApps10MessagesVcC10dataSourceSayAA9MyMessageCGSgvs + 233
20 MyApps 0x0000000105842fad _T06MyApps10MessagesVcC10reloadDatayyF + 717
21 MyApps 0x00000001058434d4 _T06MyApps10MessagesVcC10reloadDatayyFTo + 36
22 MyApps 0x00000001055d4744 _T06MyApps10MessagesVcC11viewDidLoadyyF + 2148
23 MyApps 0x00000001055d5a94 _T06MyApps10MessagesVcC11viewDidLoadyyFTo + 36
24 UIKit 0x0000000109855191 -[UIViewController loadViewIfRequired] + 1215
25 UIKit 0x00000001098555d4 -[UIViewController view] + 27
26 UIKit 0x0000000109886c6e -[UINavigationController _startCustomTransition:] + 945
27 UIKit 0x000000010989d5e2 -[UINavigationController _startDeferredTransitionIfNeeded:] + 714
28 UIKit 0x000000010989e8cc -[UINavigationController __viewWillLayoutSubviews] + 150
29 UIKit 0x0000000109af6bd7 -[UILayoutContainerView layoutSubviews] + 231
30 UIKit 0x0000000109780808 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
31 QuartzCore 0x000000010931061a -[CALayer layoutSublayers] + 177
32 QuartzCore 0x000000010931482b _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
33 QuartzCore 0x000000010929b29f _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
34 QuartzCore 0x00000001092c8940 _ZN2CA11Transaction6commitEv + 568
35 UIKit 0x00000001096d9f8c _afterCACommitHandler + 272
36 CoreFoundation 0x0000000108492607 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
37 CoreFoundation 0x000000010849255e __CFRunLoopDoObservers + 430
38 CoreFoundation 0x0000000108476b81 __CFRunLoopRun + 1537
39 CoreFoundation 0x000000010847630b CFRunLoopRunSpecific + 635
40 GraphicsServices 0x00000001104bea73 GSEventRunModal + 62
41 UIKit 0x00000001096b10b7 UIApplicationMain + 159
42 MyApps 0x0000000105755ac7 main + 55
43 libdyld.dylib 0x000000010cf0e955 start + 1
44 ??? 0x0000000000000001 0x0 + 1
)

Using AudioKit's AKHighPassFilter to filter frequencies

I'm attempting to filter out frequencies below a specified threshold with AudioKit. I'm using AKHighPassFilter to accomplish this.
func playSound(duration: Int, frequencyRange: Range<Double>) {
generator = AKOperationGenerator() { parameters in
let volume = AKOperation.sineWave(frequency: parameters[0]).scale(minimum: 0, maximum: 0.1)
let jitter = AKOperation.jitter(amplitude: parameters[1], minimumFrequency: lowerFrequency, maximumFrequency: upperFrequency)
return AKOperation.sineWave(frequency: jitter, amplitude: volume)
}
generator!.parameters = [baseFrequency, amplitude]
// Exception thrown at this line after method called 1 time
var highPassFilter = AKHighPassFilter(generator)
highPassFilter.cutoffFrequency = frequencyRange.lowerBound
highPassFilter.resonance = 0
AudioKit.output = highPassFilter
AudioKit.start()
generator?.play()
}
The first time I call playSound(duration:, frequencyRange:), it works fine. Once I stop AudioKit and attempt to play a sound a second time, an exception is thrown at this line:
var highPassFilter = AKHighPassFilter(generator)
Here is the console output from the crash:
2017-05-01 14:32:01.169 MyApp[18123:3459824] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: [_nodes containsObject: node]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109ea7b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010990c141 objc_exception_throw + 48
2 CoreFoundation 0x0000000109eabcf2 +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x000000010cdc3a9e _Z19AVAE_RaiseExceptionP8NSStringz + 158
4 AVFAudio 0x000000010cdc9cbb _ZN17AVAudioEngineImpl10DetachNodeEP11AVAudioNodeb + 421
5 AVFAudio 0x000000010cdc9ad0 -[AVAudioEngine detachNode:] + 67
6 AudioKit 0x0000000108d3bee4 _TToFC8AudioKit6AKNodeD + 84
7 libobjc.A.dylib 0x0000000109920b8e _ZN11objc_object17sidetable_releaseEb + 202
8 AudioKit 0x0000000108d39a99 _TToFC8AudioKit16AKHighPassFilterE + 25
9 libobjc.A.dylib 0x000000010990a9bc _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
10 libobjc.A.dylib 0x0000000109916d34 objc_destructInstance + 129
11 libobjc.A.dylib 0x0000000109916d66 object_dispose + 22
12 AudioKit 0x0000000108d3bf1b _TToFC8AudioKit6AKNodeD + 139
13 libobjc.A.dylib 0x0000000109920b8e _ZN11objc_object17sidetable_releaseEb + 202
14 MyApp 0x00000001087301ec _TFC7MyApp11SoundPlayerClass9playSoundfT8durationSi14frequencyRangeGVs5RangeSd__T_ + 988
15 MyApp 0x000000010873a1a4 _TFC7MyApp18MainViewController13playFrequencyfCS_12FrostyButtonT_ + 2276
16 MyApp 0x000000010873a4fa _TToFC7MyApp18MainViewController13playFrequencyfCS_12FrostyButtonT_ + 58
17 UIKit 0x000000010ab63d22 -[UIApplication sendAction:to:from:forEvent:] + 83
18 UIKit 0x000000010ace825c -[UIControl sendAction:to:forEvent:] + 67
19 UIKit 0x000000010ace8577 -[UIControl _sendActionsForEvents:withEvent:] + 450
20 UIKit 0x000000010ace74b2 -[UIControl touchesEnded:withEvent:] + 618
21 UIKit 0x000000010abd149a -[UIWindow _sendTouchesForEvent:] + 2707
22 UIKit 0x000000010abd2bb0 -[UIWindow sendEvent:] + 4114
23 UIKit 0x000000010ab7f7b0 -[UIApplication sendEvent:] + 352
24 UIKit 0x000000011e3c075c -[UIApplicationAccessibility sendEvent:] + 85
25 UIKit 0x000000010b362adc __dispatchPreprocessedEventFromEventQueue + 2926
26 UIKit 0x000000010b35aa3a __handleEventQueue + 1122
27 UIKit 0x000000010b35bd08 __handleEventQueue + 5936
28 CoreFoundation 0x0000000109e4dc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x0000000109e330cf __CFRunLoopDoSources0 + 527
30 CoreFoundation 0x0000000109e325ff __CFRunLoopRun + 911
31 CoreFoundation 0x0000000109e32016 CFRunLoopRunSpecific + 406
32 GraphicsServices 0x000000010ecd4a24 GSEventRunModal + 62
33 UIKit 0x000000010ab620d4 UIApplicationMain + 159
34 MyApp 0x000000010872cb77 main + 55
35 libdyld.dylib 0x000000010fbaf65d start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Prior to adding AKHighPassFilter, the method worked fine. I welcome suggestions re: how to resolve this crash. Thank you for reading.
I think the main problem here is that you are recreating all your objects on every playSound call as well as setting the AudioKit.output in your play method everytime it's called. What you want to do is to create your object chain in an initialization routine, then just change parameters as needed after that. All the connections only need to be established once. One technique is to use AKMixer as your input or output and add and remove nodes from it. For example a high pass filter could be filters the output of an AKMixer. This mixer could have any number of nodes attached to it. AVAudioEngine can be somewhat touchy about nodes removed or added when it's running.

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:.

i fail to understand these 2 crash reports

Since i received comments of crashes but the app never crashes for me, I now use critterism to hunt down crashes.
I received one report that pointed to me to an error by me. It was easy, since the method name was given and i
could look in my code what might crash. So far, so good.
But i also have the following two that puzzle me.
To me it looks like the app crashes in some internal apple library.( Most likely due to me feeding it some broken stuff...)
There is no call from my code in the crash, so where do start looking?
Does anyone understand these crashes?
Any idea how i can catch these and maybe get some more crash info?
No.1:
0 CoreFoundation 0x3585f88f __exceptionPreprocess + 162
1 libobjc.A.dylib 0x37c06259 objc_exception_throw + 32
2 CoreFoundation 0x35862a9b -[NSObject doesNotRecognizeSelector:] + 174
3 CoreFoundation 0x35861915 ___forwarding___ + 300
4 CoreFoundation 0x357bc650 _CF_forwarding_prep_0 + 48
5 UIKit 0x332f3efb -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 546
6 UIKit 0x332f2f39 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 916
7 UIKit 0x332f2763 -[UITableView layoutSubviews] + 206
8 UIKit 0x33296f37 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 182
9 CoreFoundation 0x357be1fb -[NSObject performSelector:withObject:] + 42
10 QuartzCore 0x3268eaa5 -[CALayer layoutSublayers] + 216
11 QuartzCore 0x3268e6bd _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 216
12 QuartzCore 0x32692843 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 226
13 QuartzCore 0x3269257f _ZN2CA11Transaction6commitEv + 314
14 QuartzCore 0x326ba911 _ZN2CA11Transaction5flushEv + 44
15 QuartzCore 0x326ba8e3 +[CATransaction flush] + 34
16 UIKit 0x332a1fb1 _afterCACommitHandler + 52
17 CoreFoundation 0x35833b1b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
18 CoreFoundation 0x35831d57 __CFRunLoopDoObservers + 258
19 CoreFoundation 0x358320b1 __CFRunLoopRun + 760
20 CoreFoundation 0x357b54a5 CFRunLoopRunSpecific + 300
21 CoreFoundation 0x357b536d CFRunLoopRunInMode + 104
22 GraphicsServices 0x37451439 GSEventRunModal + 136
23 UIKit 0x332c1cd5 UIApplicationMain + 1080
24 Wohnungssuche 0x000d5218 start + 40
No. 2:
Thread: Unknown Name (Crashed)
0 libobjc.A.dylib 0x35beb5d0 objc_msgSend + 16 + 15
1 UIKit 0x39fb0541 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 409 + 408
2 UIKit 0x39f95361 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1317 + 1316
3 UIKit 0x39fac7ff -[UITableView layoutSubviews] + 207 + 206
4 UIKit 0x39f68897 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 259 + 258
5 QuartzCore 0x34ab74eb -[CALayer layoutSublayers] + 215 + 214
6 QuartzCore 0x34ab708d _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 461 + 460
7 QuartzCore 0x34ab7fb1 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 17 + 16
8 QuartzCore 0x34ab799b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 239 + 238
9 QuartzCore 0x34ab77ad _ZN2CA11Transaction6commitEv + 317 + 316
10 QuartzCore 0x34aee7df _ZN2CA7Display11DisplayLink8dispatchEyy + 255 + 254
11 QuartzCore 0x34aee6d9 _ZN2CA7Display16IOMFBDisplayLink8callbackEP21__IOMobileFramebufferyyyPv + 65 + 64
12 IOMobileFramebuffer 0x375f0fd7 IOMobileFramebufferVsyncNotifyFunc + 155 + 154
13 IOKit 0x3282a5ad IODispatchCalloutFromCFMessage + 193 + 192
14 CoreFoundation 0x3918288b __CFMachPortPerform + 119 + 118
15 CoreFoundation 0x3918d3e7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 35 + 34
16 CoreFoundation 0x3918d38b __CFRunLoopDoSource1 + 139 + 138
17 CoreFoundation 0x3918c20f __CFRunLoopRun + 1383 + 1382
18 CoreFoundation 0x390ff23d CFRunLoopRunSpecific + 357 + 356
19 CoreFoundation 0x390ff0c9 CFRunLoopRunInMode + 105 + 104
20 GraphicsServices 0x3344933b GSEventRunModal + 75 + 74
21 UIKit 0x39fb9291 UIApplicationMain + 1121 + 1120
Thanks for your help!
The crash point in both cases is the same:
UIKit 0x39fb0541 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 409 + 408
In the first case, the table view was trying to call a method on an instance that does not implement said method. The second crash was caused by trying to message garbage.
Thus, the most likely conclusion is that both crashes are symptoms of a single problem; you have an object that is being prematurely released or over-released.
In particular, your table view's data source is being released before or while a table is reloading.
I suspect that UITableView is trying to call the data source's method to create a cell. You could confirm this by setting a breakpoint on said method and looking at the stack trace. If my bet is correct, you'll see the _createPreparedCellForGlobal... method in the trace.
Without knowing details of your app, hard to say. Most likely, this is timing related issue between data being loaded on the screen and the user doing something that causes a request to be canceled earlier than the table view is done loading, causing your data source to be deallocated out from under the table (which can happen because the table view has an assign reference to your object; a non-retaining reference).
To try and reproduce, focus on:
• slow network connection or variable bandwidth (if your app is client/server)
• do things the user might do that causes operations to cancel
• quickly navigate between views without waiting for the update to complete drawing
In your comments, you mention that you are trying on "two different iPhones". Try on other device types and across different network configurations.

Resources