Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Using with firebase #336

Closed jameswasher closed 7 years ago

jameswasher commented 7 years ago

I have no problem following the examples with hard coded data, but when I try to implement IGListKit with firebase I run into issues. I get the following error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 21. The number of items contained in an existing section after the update (10) must be equal to the number of items contained in that section before the update (3), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

Here is a minimal example:

https://github.com/jameswasher/IGListTest

I'm probably not loading the data correctly in CardLoader.swift. I exported my firebase data into a file called firebase-json.json so you can see that data that I'm using.

New issue checklist

General information

rnystrom commented 7 years ago

@jameswasher thanks for providing a sample project! I downloaded and fired it up, but everything loads just fine for me. Is there something specific I need to do to reproduce the issue?

simulator screen shot dec 15 2016 6 35 14 pm

jameswasher commented 7 years ago

Thanks for taking a look!

Strange. It crashes for me every time. I'm not doing anything special. I tried running on the simulator and my phone. Here is what the console says

2016-12-15 19:43:18.019 IGListTesting[36662:824504] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist

2016-12-15 19:43:18.985 IGListTesting[36662] [Firebase/Core][I-COR000001] Configuring the default app.

2016-12-15 19:43:19.000 IGListTesting[36662:] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started

2016-12-15 19:43:19.001 IGListTesting[36662:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu http://goo.gl/Y0Yjwu)

2016-12-15 19:43:19.011: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

2016-12-15 19:43:19.131 IGListTesting[36662:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist

2016-12-15 19:43:19.158 IGListTesting[36662:] <FIRAnalytics/WARNING> The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://goo.gl/9vSsPb http://goo.gl/9vSsPb

2016-12-15 19:43:19.339 IGListTesting[36662:] <FIRAnalytics/INFO> Firebase Analytics enabled

2016-12-15 19:43:19.516: <FIRInstanceID/WARNING> STOP!! Will reset deviceID from memory.

2016-12-15 19:43:19.805: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"

2016-12-15 19:43:19.911 IGListTesting[36662] [Firebase/Core][I-COR000019] Clearcut post completed.

2016-12-15 19:43:20.144: <FIRInstanceID/WARNING> STOP!! Will reset deviceID from memory.

*2016-12-15 19:43:21.180 IGListTesting[36662:824504] ** Assertion failure in -[IGListCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UICollectionView.m:5585

*2016-12-15 19:43:21.186 IGListTesting[36662:824504] ** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 58. The number of items contained in an existing section after the update (10) must be equal to the number of items contained in that section before the update (5), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

*** First throw call stack:

(

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

On Thu, Dec 15, 2016 at 5:35 PM, Ryan Nystrom notifications@github.com wrote:

@jameswasher https://github.com/jameswasher thanks for providing a sample project! I downloaded and fired it up, but everything loads just fine for me. Is there something specific I need to do to reproduce the issue?

[image: simulator screen shot dec 15 2016 6 35 14 pm] https://cloud.githubusercontent.com/assets/739696/21246205/4261c5a0-c2f5-11e6-8f3a-7e56710713dc.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Instagram/IGListKit/issues/336#issuecomment-267476391, or mute the thread https://github.com/notifications/unsubscribe-auth/AIF8ZhtFsXvwwnQlcIIOxgxQ7ccKIllLks5rIc7OgaJpZM4LORcu .

jameswasher commented 7 years ago

Just to make sure there are no differences from the code I uploaded to github I downloaded a zip from the link I posted above and ran that project. Same crash. It takes a few seconds to crash.

jameswasher commented 7 years ago

I ran the app again on my phone while not connected to Xcode and it worked. Very strange. On Thu, Dec 15, 2016 at 7:46 PM James Washer james.washer@gmail.com wrote:

Thanks for taking a look!

Strange. It crashes for me every time. I'm not doing anything special. I tried running on the simulator and my phone. Here is what the console says

2016-12-15 19:43:18.019 IGListTesting[36662:824504] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist

2016-12-15 19:43:18.985 IGListTesting[36662] [Firebase/Core][I-COR000001] Configuring the default app.

2016-12-15 19:43:19.000 IGListTesting[36662:] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started

2016-12-15 19:43:19.001 IGListTesting[36662:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu http://goo.gl/Y0Yjwu)

2016-12-15 19:43:19.011: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

2016-12-15 19:43:19.131 IGListTesting[36662:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist

2016-12-15 19:43:19.158 IGListTesting[36662:] <FIRAnalytics/WARNING> The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://goo.gl/9vSsPb http://goo.gl/9vSsPb

2016-12-15 19:43:19.339 IGListTesting[36662:] <FIRAnalytics/INFO> Firebase Analytics enabled

2016-12-15 19:43:19.516: <FIRInstanceID/WARNING> STOP!! Will reset deviceID from memory.

2016-12-15 19:43:19.805: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"

2016-12-15 19:43:19.911 IGListTesting[36662] [Firebase/Core][I-COR000019] Clearcut post completed.

2016-12-15 19:43:20.144: <FIRInstanceID/WARNING> STOP!! Will reset deviceID from memory.

*2016-12-15 19:43:21.180 IGListTesting[36662:824504] ** Assertion failure in -[IGListCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UICollectionView.m:5585

*2016-12-15 19:43:21.186 IGListTesting[36662:824504] ** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 58. The number of items contained in an existing section after the update (10) must be equal to the number of items contained in that section before the update (5), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

*** First throw call stack:

(

  • 0 CoreFoundation 0x000000010253634b __exceptionPreprocess + 171*

  • 1 libobjc.A.dylib 0x0000000101f9e21e objc_exception_throw + 48*

  • 2 CoreFoundation 0x000000010253a442 +[NSException raise:format:arguments:] + 98*

  • 3 Foundation 0x0000000101b34e4d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195*

  • 4 UIKit 0x0000000103c261db -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:]

  • 17367*

  • 5 UIKit 0x0000000103c2edba -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:] + 71*

  • 6 UIKit 0x0000000103c2f0fc -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:]

  • 432*

  • 7 UIKit 0x0000000103c2ef29 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:]

  • 91*

  • 8 UIKit 0x0000000103c2eeab -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 74*

  • 9 UIKit 0x0000000103c2ee00 -[UICollectionView performBatchUpdates:completion:] + 53*

  • 10 IGListKit 0x000000010180ee1c -[IGListAdapterUpdater performBatchUpdatesWithCollectionView:] + 2956*

  • 11 IGListKit 0x0000000101811b95 __54-[IGListAdapterUpdater queueUpdateWithCollectionView:]_block_invoke + 357*

  • 12 libdispatch.dylib 0x00000001054c4980 _dispatch_call_block_and_release + 12*

  • 13 libdispatch.dylib 0x00000001054ee0cd _dispatch_client_callout + 8*

  • 14 libdispatch.dylib 0x00000001054ce8d6 _dispatch_main_queue_callback_4CF + 406*

  • 15 CoreFoundation 0x00000001024fa4f9 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9*

  • 16 CoreFoundation 0x00000001024bff8d __CFRunLoopRun + 2205*

  • 17 CoreFoundation 0x00000001024bf494 CFRunLoopRunSpecific + 420*

  • 18 GraphicsServices 0x000000010687ea6f GSEventRunModal + 161*

  • 19 UIKit 0x00000001032c9964 UIApplicationMain + 159*

  • 20 IGListTesting 0x00000001006c814f main + 111*

  • 21 libdyld.dylib 0x000000010553a68d start + 1*

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

On Thu, Dec 15, 2016 at 5:35 PM, Ryan Nystrom notifications@github.com wrote:

@jameswasher https://github.com/jameswasher thanks for providing a sample project! I downloaded and fired it up, but everything loads just fine for me. Is there something specific I need to do to reproduce the issue?

[image: simulator screen shot dec 15 2016 6 35 14 pm] https://cloud.githubusercontent.com/assets/739696/21246205/4261c5a0-c2f5-11e6-8f3a-7e56710713dc.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Instagram/IGListKit/issues/336#issuecomment-267476391, or mute the thread https://github.com/notifications/unsubscribe-auth/AIF8ZhtFsXvwwnQlcIIOxgxQ7ccKIllLks5rIc7OgaJpZM4LORcu .

jameswasher commented 7 years ago

I decided to move the title into the section like in the WeatherSectionController of the Marslink tutorial. This allows the user to collapse and expand the sections. When I did that I don't get a crash anymore.

Thanks again for taking a look at my question and for open sourcing this awesome framework!

rnystrom commented 7 years ago

Hmph, I should really get moving on #310 which might help a lot more.

@jameswasher one issue I do see browsing the project is that the numberOfItems is driven by a mutable array that is changed arbitrarily by Firebase. I would recommend storing a copy of the Lesson model and replacing it when things change.

I'd recommend some sort of immutable model setup though. You can pass a Lesson model to your section controller, but then maybe transform it into a struct LessonSectionViewModel or something when it changes.

edit: Looks like the mutable cards property can also be appeneded here and here. This aligns w/ the crash where the numberOfItems was 5 but is now 10 (appending) w/out calling collectionContext.insert(...).

jameswasher commented 7 years ago

That makes sense! I will do that.