In iOS 13,
NSFetchedResultsController gained support for delivering changes to its content as a
NSDiffableDataSourceSnapshot via. its delegate. The snapshot contains the contents of the controller and can be used to populate a table or collection view complete with animations for content updates.
Unfortunately the API has a few issues. The way it’s bridged from Objective-C to Swift makes using it a bit confusing and it doesn’t match all the functionality of the older delegate methods. In this post I’ll document a couple of the issues I’ve run into and how I’ve worked around them.
I published a new project on GitHub today. It’s a screensaver for macOS called Normal. It simply applies a Gaussian blur to the contents of the screen. I wrote it a year ago when I was procrastinating from my dissertation. Go ahead and check it out on GitHub.
I needed a way to present non-modal alerts inside an app I’m working on and wanted to use a banner system that’s a bit like what Tweetbot does. I ended up writing a
UIView subclass called
BannerView that I’ve open sourced for anybody to use.
TL;DR: You can’t name a Core Data attribute
new* in Objective-C or Swift because of how automatic reference counting interacts with manual reference counting. If you do, you’ll crash unreliably when your Core Data stack is deallocated.
I’ve spent the better part of a day trying to fix this hard to track down bug in my Core Data stack that was causing a crash. The crash was introduced when I added a new entity to my object model. The
NSManagedObject subclass looked a little like this:
I ran into an issue while writing property validation methods for a Core Data stack where the methods simply weren’t being called. After a bit of head scratching I realised it was because the methods needed to be annotated with
@objc. This wasn’t needed in Swift 3 because
@objc was inferred on all methods of subclasses of
NSObject; however, the behaviour of
@objc inference changed in Swift 4. Now, subclasses of
NSObject must explicitly mark methods that need to be accessible from Objective-C. This took longer to realise than it should have since the Core Data documentation’s sample code for property-level validation hasn’t been updated for Swift 4.