Post

Replies

Boosts

Views

Activity

What is CodableWithConfiguration used for?
Hi, I noticed the CodableWithConfiguration protocol in the section of the talk about AttributedString. I'm not really sure what purpose it serves and how it fits in with the original Codable protocol. As far as I can tell there aren't (as of beta 3) any ways to decode/encode objects conforming to this protocol with JSONDecoder/PropertyListDecoder/TopLevelDecoder. I expected there to be something like JSONDecoder().decode(_:from:configuration:) to match the existing JSONDecoder().decode(_:from:). It looks like only the keyed and un-keyed coding containers (but not single value containers) provide ways to decode/encode such objects. I guess my questions are: What are the use cases for these new protocols? Is the configuration object designed to replace the userInfo dictionary on Decoder/Encoder? If I currently pass required information to decoders/encoders via this userInfo dictionary, should I consider using CodableWithConfiguration to avoid typecasting from Any? Why is support for decoding/encoding these objects so limited compared with the original Codable protocols? Thanks!
0
0
631
Jul ’21
What is the proper way to use NSFetchedResultsController with diffable data sources in Swift?
In Swift, a Core Data fetched results controller can vend diffable data source snapshots to its delegate which greatly simplifies using lists. In Swift this snapshot is an NSDiffableDataSourceSnapshotReference, so to create my data source I've been doing: let dataSource = UICollectionViewDiffableDataSourceReference(collectionView: collectionView) { [unowned self] (collectionView, indexPath, _) -> UICollectionViewCell? in             let item = self.fetchedResultsController.object(at: indexPath)             // configure and return cell } Is it correct to be using the fetched results controller to get the object or is there a better way? I noticed that the item identifier is an NSManagedObjectID so should I be using that and a MOC instead of the FRC? Also, a couple of months ago when some documentation was finally added for diffable data sources I noticed comments warning against using the -Reference versions of the data sources and snapshots. Apparently it is important to bridge the snapshots like so: let snapshot = snapshotReference as NSDiffableDataSourceSnapshot<Int, UUID> If this is the case, what purpose does the UUID serve and how can I use it to get the corresponding managed object?
0
0
886
Jul ’20