Order of Variables and parameters of struct

Hi there !! How are you!!! I have one for you

a) ¿When put variables in body, and when outside ?

  • In this case let url is recommended put together the others variables?

b) if I write var video: Video. and call the Struct PlayerView from ContentView why this variable is a parameter of my struct PlayerView, but not videoRatio, for example.?

c) ¿My struct PlayerView can be much better a class? If this class or struct consume more memory? Depend of size of videos.

Thanks a lot.!

import SwiftUI
import AVKit

struct PlayerView: View {
    var video:Video
    let videoRatio: CGFloat = 1080 / 1920
    
    var body: some View {
        
        let url = URL(string: video.url)
        GeometryReader { geo in
            VStack {
                Text(video.title)
                    .font(.title)
                    .bold()
            
                if url != nil {
                    VideoPlayer(player: AVPlayer(url: url!))
                        .frame(height: geo.size.width * videoRatio)
                }
                
                Spacer()
                
            }
        }

    }
}

Variables, var, cannot be created inside the body property or a View.
A let can be used inside a View because it is a constant.

so let url = URL(string: video.url) is OK.

var video: Video says that video is of type Video but is not assigned a value so that is why it must be passed a value when PlayerView is called.

let videoRatio: CGFloat = 1080 / 1920 says that videoRatio is of type CGFloat and is equal to 1080 / 1920 which means videoRatio has a value.

In SwiftUI, Views are structs.

From stackoverflow : Can a class be a View in SwiftUI? - Stack Overflow

Thanks a lot!!