SwiftUI tutorial Animating view and transitions section 3/4/5 Hike folder issue

In section 4/5 of the Animating and transitions tutorial, the steps show code that looks like it is missing pieces of the code that is contained in the actual hike folder. These pieces include :


#Preview {


    VStack {


        HikeView(hike: ModelData().hikes[0])


            .padding()


        Spacer()


    }


}



at the bottom of the HikeView file , and



func rangeOfRanges<C: Collection>(_ ranges: C) -> Range<Double>


    where C.Element == Range<Double> {


    guard !ranges.isEmpty else { return 0..<0 }


    let low = ranges.lazy.map { $0.lowerBound }.min()!


    let high = ranges.lazy.map { $0.upperBound }.max()!


    return low..<high


}




func magnitude(of range: Range<Double>) -> Double {


    range.upperBound - range.lowerBound


}


#Preview {


    let hike = ModelData().hikes[0]


    return Group {


        HikeGraph(hike: hike, path: \.elevation)


            .frame(height: 200)


        HikeGraph(hike: hike, path: \.heartRate)


            .frame(height: 200)


        HikeGraph(hike: hike, path: \.pace)


            .frame(height: 200)


    }


}


located at the bottom of the HikeGraph file


when these code pieces are used properly, the code runs fine. Though, the HikeGraph preview does look a bit jumbled. I don't know if this is an error for not including these or if I used the code improperly but somehow got the correct result.



Mac mini (M2, 2023)

Posted on May 7, 2024 11:17 AM

Reply

There are no replies.

SwiftUI tutorial Animating view and transitions section 3/4/5 Hike folder issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.