UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Apple SwiftUI tutorial bug?

Forums > SwiftUI

In Apple's SwiftUI Tutorials: Animating Views and Transitions, toggling between "Elevation", "Heart Rate", and "Pace" in the HikeDetail view does not change the data displayed as expected, rather it slightly shifts the graph up or down.

This can be reproduced in the "Complete" version of the project offered by Apple in the "Project files" downloads, in Xcode 11.5 (11E608c).

The code looks completely right to me, and I think I had seen the expected behavior running once...can anyone help explain?

Expected:

Expected

Actual:

Actual

3      

I just ran into this issue as well. It is a bit disappointing that this bug is in tutorial code, but it is an opportunity to take a deeper dive into Swift animations and transitions!

This will not be of much value but I have noticed that if you remove the slide transition from each GraphCapsule in HikeGraph.swift, then the capsules will update correctly when toggling between "Elevation", "Heart Rate", and "Pace". However, and obviously, we lose the custom slide-in transition from each GraphCapsule upon showing the HikeGraph.

I find removing the slide transition to be a "lesser of the two evils" solution when deciding between it or not having each GraphCapsule update upon toggling the Observation buttons.

I will keep experimenting and will update if I come across any solutions. Thanks to @Calvin-Xu for bringing this issue up in the first place.

Quick Edit:

I have found another link to this issue as well in Apple's developer forums.

2      

Have you posted on Apple Developer Forums that any type of problem you have to had check here first! Maybe someone at Apple will realised that thier tutorial is flawed.

2      

Hi there,

Solution and a reference to the changes that lead to the issue are posted in the forum thread: https://developer.apple.com/forums/thread/131041

There is an open question in there: why it doesn't work only when .transition is applied? Please share your thoughts.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.