4 Replies
      Latest reply on Jun 17, 2019 2:05 PM by IngmarStein
      anwill999 Level 1 Level 1 (10 points)

        Using the iOS 13 beta SDK, I'm trying to drive updates to a UICollectionView using a NSFetchedResultsController and the new NSDiffableDataSource APIs as outlined in session 230 - 'Building Apps with Core Data'.

         

        Using the NSFetchedResultsController delegate method 'didChangeContent withSnapshot', I'm trying to for cast the NSDiffableDataSourceSnapshotReference to a NSDiffableDataSourceSnapshot as shown in the slides. However, I'm running into a compile error when trying to do so - "Generic parameter 'SectionIdentifierType' could not be inferred in cast to 'NSDiffableDataSourceSnapshot'".

         

        func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference<NSManagedObjectID, NSString>) {
                
                dataSource.apply(snapshot as! NSDiffableDataSourceSnapshot, animatingDifferences: true)
            }
        

         

        Is Anyone else seeing this error? Any thoughts on how I can get past it?

         

        I've also filed a feedback report - FB6135082.

         

        Thanks,

         

        Andrew

        • Re: Unable to cast NSDiffableDataSourceSnapshotReference
          IngmarStein Level 1 Level 1 (15 points)

          This doesn't look ready, yet. The example is clearly wrong, as the cast operates on unrelated types and always fails when you add the missing generic paramaters, given the following class declarations in beta 1:

           

          open class NSDiffableDataSourceSnapshotReference<sectionidentifiertype, itemidentifiertype=""> : NSObject, NSCopying where SectionIdentifierType : AnyObject, ItemIdentifierType : AnyObject {
          public class NSDiffableDataSourceSnapshot<sectionidentifiertype, itemidentifiertype=""> where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable {
            • Re: Unable to cast NSDiffableDataSourceSnapshotReference
              IngmarStein Level 1 Level 1 (15 points)

              Also, if you try to use the NSDiffableDataSourceSnapshotReference that is passed to your delegate in controller(_, didChangeContentWith:), you get all sorts of type errors which seem to indicate a problem with how this type is imported into Swift:

               

              (lldb) po snapshot.sectionIdentifiers
              Precondition failed: NSArray element failed to match the Swift Array Element type
              Expected NSManagedObjectID but found __NSCFConstantString: 
              …
              
              (lldb) po snapshot.itemIdentifiers
              Precondition failed: NSArray element failed to match the Swift Array Element type
              Expected NSString but found NSTemporaryObjectID_0: 
              …
              

               

              This lets me think that NSDiffableDataSourceSnapshotReference<NSManagedObjectID, NSString> should probably be NSDiffableDataSourceSnapshotReference<NSString, NSManagedObjectID>.

            • Re: Unable to cast NSDiffableDataSourceSnapshotReference
              funkenstrahlen Level 1 Level 1 (0 points)

              Can confirm this issue when I try to use this on a UITableView. I hope Apple addresses this in a future beta. Everyone send a bugreport!