Swift You and I
A blog about SwiftUI and related Apple ecosystem technologies

Welcome to Swift You and I! Connect with us on Twitter, Medium and DEV Community. And don’t forget to checkout the blog’s official companion app Working Examples for SwiftUI!


Line-Wrapping Stacks
Splitting horizontal stacks into multiple lines
@diegolavalledev Oct 11, 2020

Since its inception SwiftUI has provided us with automatic line-wrapping within text views as well as for concatenations of text views. But there is nothing equivalent that can be applicable to mixed arbitrary views. This is however possible in UIKit by way of collection views configured with what is called a flow layout object. Here we are taking a different approach. Read on to find out!

Read more

Check out our latest interactive Working Example running natively, right on your device!

Pausing and Reversing SwiftUI Animations
Use regular views to control the flow
@diegolavalledev Aug 12, 2020

Animations and transitions are decisively one of SwiftUI’s fortes. The framework allows us to go as deep as we want in handling specifics like timing function and duration parameters. Moreover it gives us sophisticated tools like the Animatable protocol to completely customize behavior. Here we are going to rely on the more constricted AnimatableModifier protocol to show how we can manually pause and resume and animation as well as adding the ability to reverse and loop over.

Read more

Welcome to Swift You and I! Connect with us on Twitter, Medium and DEV Community. And don’t forget to checkout the blog’s official companion app Working Examples for SwiftUI!


Computed properties as synthesized bindings
Gain control over your bindings' behavior
@diegolavalledev Aug 6, 2020

Computed properties are useful in so many ways and within the context of SwiftUI they are even more powerful. We can use them to split up our view body while keeping access to the same data. Or we can derive new values from our state that will recalculate with every change. We can also use computed properties in model objects, observing and even setting their values via synthesized bindings.

Read more

On-demand bindings
Create custom bindings when you need them
@diegolavalledev Jan 19, 2020

Bindings are used to pass parts of our state down to a subview that might later on make changes to said state. We typically rely on the @State and @Binding property wrappers to generate bindings for us but bindings can also be constructed programmatically. In fact there’s a handful of cases in which creating bindings in an on-demand manner may just be the preferred option.

Read more

Keyboard-aware views
Learn how to make room for the software keyboard
@diegolavalledev Jan 12, 2020

Sometimes we want to give our views a chance to react to the software keyboard being pulled up. This could be particularly useful in forms with text input where the keyboard might cover the very field we are typing into. We can solve this in SwiftUI with a little help from some old friends.

Read more

Codable observable objects
Integrate your models with Combine
@diegolavalledev Jan 5, 2020

Complying to the Codable protocol is simple thanks to synthesized initializers and coding keys. Similarly making your class observable using the Combine framework is trivial with ObservableObject. But attempting to merge these two protocols in a single implementation poses a few obstables. Let’s find out!

Read more

SwiftUI Scroll Magic
Control and react to the current position
@diegolavalledev Sep 28, 2019

Scroll views in SwiftUI are very straight-forward but give us no information or control over the current position of its content. So how can we detect for instance that the user has scrolled beyond certain threshold off the top?

Read more

Detecting When an Animation Has Ended
Perform actions on completion
@diegolavalledev Sep 21, 2019

Whenever a SwiftUI animation is triggered, its state is updated immediately regardless of the duration. The Animation struct does not provide us with any sort of callback to indicate whether it has completed. So how can we detect when our views have stopped animating?

Read more

Form Validation with Combine
Back your form with event-driven logic
@diegolavalledev Sep 14, 2019

In WWDC 2019 session Combine in Practice we learned how to apply the Combine Framework to perform validation on a basic sign up form built with UIKit. Now we want to apply the same solution to the SwiftUI version of that form which requires some adaptation.

Read more

You Don't Need UIImage
Correct usage of the Image view
@diegolavalledev Sep 7, 2019

In SwiftUI Image view provides a way to initialize it using UIKit’s UIImage. This was used to work-around some early issues with Swift UI which prevented custom symbols to be scaled and colored.

Read more