Learn more about Swift
Understanding Swift’s OptionSet
Published on: August 18, 2020Every once in a while I look at a feature in Swift and I fall down a rabbit hole to explore it so I can eventually write about it. The OptionSet protocol is one of these Swift features. If you’ve ever written an animation and passed it a list of options like this, you have […]
Read postIf you’ve ever wanted to decode a bunch of JSON data into NSManagedObject instances you’ve probably noticed that this isn’t a straightforward exercise. With plain structs, you can conform your struct to Codable and you convert the struct from and to JSON data automatically. For an NSManagedObject subclass it’s not that easy. If your Core […]
Read postUnit testing is an important skill in the toolbox of any engineer. Knowing how to write a reliable, robust test suite helps you write reliable and robust code. If you’ve followed my introduction to unit testing part one and part two, or if you’re experienced with unit testing you know that your tests should run […]
Read postIn WWDC2020’s session Lists in UICollectionView a slide is shown where a UICollectionViewListCell’s separator inset is updated by assigning a new leading anchor to separatorLayoutGuide.leadingAnchor. Unfortunately, this doesn’t work in when you try to do it. To set the separator inset for a UICollectionViewListCell you can update the leading anchor constraint by overriding updateConstraints in […]
Read postApple provides several accessory types that you can use to apply certain affordances to a UICollectionViewListCell. However, sometimes these options don’t suit your needs and you’re looking for something more customizable. To add a custom accessory to a list cell instead of a standard one, you use the .custom accessory type. The initializer for this […]
Read postIn iOS 14 Apple added the ability for developers to create collection views that look and feel like table views, except they are far, far more powerful. To do this, Apple introduced a new UICollectionViewCell subclass called UICollectionViewListCell. This new cell class allows us to implement several tableviewcell-like principles, including accessories. Adding accessories to a […]
Read postIn iOS 14 Apple added the ability for developers to create collection views that look and feel like table views, except they are far, far more powerful. To do this, Apple introduced a new UICollectionViewCell subclass called UICollectionViewListCell. This new cell class allows us to implement several tableviewcell-like principles, including swipe actions. You can add […]
Read postConfigure collection view cells with UICollectionView.CellRegistration
Updated on: September 30, 2020In iOS 14 you can use the new UICollectionView.CellRegistration class to register and configure your UICollectionViewCell instances. So no more let cellIdentifier = "MyCell", no more collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) and best of all, you no longer need to cast the cell returned by dequeueReusableCell(withReuseIdentifier:for:) to your custom cell class. Adopting UICollectionView.CellRegistration in your project […]
Read postA Double and Float are both used to represent decimal numbers, but they do so in slightly different ways. If you initialize a decimal number in Swift using as shown below, the Swift compiler will assume that you meant to create a Double: let val = 3.123 // val is inferred to be Double The […]
Read postProperty wrappers are a feature that was introduced in Swift 5.1 and they play a huge role in SwiftUI and Combine which are two frameworks that shipped alongside Swift 5.1 in iOS 13. The community was quick to create some useful examples that were embraced by folks relatively quickly. As a user of property wrappers, […]
Read post