Simulating Push Notifications on the iOS Simulator

Testing push notifications can be a challenging task, especially if you don’t have a physical device on hand to test with. Fortunately, there are tools available that allow you to test push notifications on the iOS simulator. Let’s explore how to use the simctl command line tool to simulate push notifications on the iOS simulator. Prerequisites Before we get started, you’ll need to make sure you have the following: A Mac with Xcode and the iOS simulator installed An app installed on the iOS simulator that you want to send push notifications to Grant Permissions Before you can schedule or deliver notifications, you need to ask the user for permission to do so....

January 6, 2023 · Mike Gopsill ·  simctl

Shake to Debug View Size

Ever wanted to quickly resize the simulator iOS screen so you can test how your view performs on smaller devices. Enter shake to debug. Shake is a good motion to use for presenting a debug menu because it’s easy to detect and can be done from anywhere. Whenever a user shakes their iPhone, the OS will call the motionEnded instance method of any UIResponder. As most UI elements inherit from UIResponder it’s easy to override motionEnded wherever we need, then display a debug menu when it happens....

January 5, 2023 · Mike Gopsill ·  UIKit

Autolayout DSL

Programmatic layout is great, but Apple’s Auto Layout is a bit heavy. Apples take on this: Whenever possible, use Interface Builder to set your constraints. Not the best advice considering the previously discussed benefits of programmatic layouts. Many frameworks exist to alleviate the problem. SnapKit, PureLayout and Anchorage are all viable options. In most cases introducing relevant dependencies is fine and has many benefits but the negatives are: requiring dependency management (SPM, CocoaPods, Carthage) adding additional imports unneeded code bloat, such as importing Alamofire for one simple network request I build many little projects....

UIStackView

The UIStackView class aligns arrangedSubviews in a column or row. It reduces the amount of auto layout code required for grid-like layouts. It also handles constraints dynamically when you add, hide, insert and remove subviews. By default stack views arrange subviews horizontally in a row. This article will use horizontal stack views for this reason. The logic can easily be applied to vertical stack views by changing the axis property to ....

January 3, 2023 · Mike Gopsill ·  UIKit

Programmatic Auto Layout UIScrollViews

Programmatic layout rules. Some benefits: Single source of truth for your UI. Less context switching from code to interface builder. Less noise from storyboards, xibs, segues etc. No XML merge conflicts. Easier to review and debug. More flexibility for if-else scenarios, animations etc. There’s probably more. UIScrollView is great too. Simple layouts nested in a scroll view are common when you don’t need a table view or collection view and the additional complexity they bring....

Diffable Data Sources

Collection views and table views need to know what data to display, where to display it and how to move it. Data sources give our collection views and table views of this data. Diffable data sources provide a more simple and more stateless way to provide our data. What is it? A diffable data source is a subclass of either UITableViewDataSource or UICollectionViewDataSource. It is generic over two Hashable types. The types are SectionIdentifierType and ItemIdentifierType....