Open in app

Sign In

Write

Sign In

Jullian Mercier
Jullian Mercier

124 Followers

Home

About

Dec 24, 2020

Swift Package Manager — Integrating resources

Declaring resources Resources can be bundled with a Swift package and then be accessed in your code. We can distinguish two types of resources : common resources (e.g interface builder files, core data files, asset catalogs, lproj folders..) and custom resources (e.g .json files, .txt files, .md files..): Adding the former is…

Swift

2 min read

Swift

2 min read


Nov 9, 2020

Combine — collect()

`collect()` is a powerful operator that enables us to receive all at once the outputs from a publisher. It collects all received elements, and emits a single array of the collection when the upstream publisher finishes. [0, 1, 2, 3].publisher .sink { (output) in print(output) }.store(in: &subscriptions) The publisher will…

Swift

1 min read

Swift

1 min read


Oct 25, 2020

SwiftUI — Creating a custom @Environment

SwiftUI enables us to access common pieces of information throughout the app using `@Environment` objects avoiding the cumbersomeness of passing data through the views. There are many built-in environments such as `openURL`, `colorScheme` or `managedObjectContext` to manage data storage with Core Data. All these environments are defined in the Swift…

Swift

3 min read

Swift

3 min read


Apr 3, 2020

Combine — Single-valued publisher

While creating a custom operator out of Combine’s built-in ones in the `Publisher` extension is a useful (and quick!) technique to harmonize some common reactive behaviors, it is sometimes necessary to provide with some more in-depth customization to achieve our goal. Combine enables us to conform to the `Publisher`, `Subscription`…

Combine

3 min read

Combine

3 min read


Mar 21, 2020

Swift — @propertyWrapper with Publisher

Property wrappers are one of Swift’s major new features enabling us to attach some specific behavior each time a property gets accessed or mutated. It comes in very handy when one needs to encapsulate some common logic such as the user defaults which are often read and written to throughout…

Swift

2 min read

Swift

2 min read


Feb 23, 2020

Combine — Creating a custom subscriber

While Combine provides with a `sink` method that conveniently « creates the subscriber and immediately requests an unlimited number of values, prior to returning the subscriber. », the framework also enables us to define our own subscriber by conforming to the `Subscriber` protocol. — Use case class CustomSubscriber: Subscriber {…

Swift

2 min read

Swift

2 min read


Feb 16, 2020

Swift — Leveraging the power of first-class functions

Functions, in Swift, are first-class citizens that can be passed as arguments, stored in properties or returned from functions. When dealing with Swift built-in functions such as `map` and `forEach`, one often ends up using the trailing closure syntax to provide with the required behavior. let stackView = UIStackView() let views…

Swift

2 min read

Swift

2 min read


Jan 2, 2020

Combine — share() and multicast()

Combine is designed around structs — which are value types — ensuring that a copy is made by the system whenever a resource is stored in a property (or passed around in functions) so it can deliver values without side-effects. extension Publishers { /// A publisher that publishes a given…

Swift

3 min read

Swift

3 min read


Dec 8, 2019

Combine — switchToLatest()

switchToLatest() is one of the most powerful operator in Combine as it enables to switch entire publisher subscriptions on the fly while canceling the pending publisher subscription, thus switching to the latest one. Only publishers that emit publishers can use the `switchToLatest()` operator. AnyPublisher<AnyPublisher<[Post], Never>, Never> Every time a publisher…

Swift

2 min read

Swift

2 min read


Nov 24, 2019

Combine — Handling UIKit’s gestures with a Publisher

While Combine doesn’t provide a built-in API to handle UIKit’s gestures yet, the Publisher and Subscription protocols give us the ability to create our own solution. — Creating a custom publisher First, let’s create a custom publisher by conforming to the Publisher protocol which is composed of two associated types namely Output and Failure. `Output`…

Swift

3 min read

Swift

3 min read

Jullian Mercier

Jullian Mercier

124 Followers

Senior iOS engineer. jullianmercier.com. @jullian_mercier.

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech