3

I am trying to make a basic iOS device details app. Trying to print the user's iOS version in a view. I have declared a variable in the ContentView.swift file.

var systemVersion = UIDevice.current.systemVersion

But, I do not know how to display this variable to the user via a view in SwiftUI.

Currently:

struct ContentView: View {

@State private var selectedTab = Tab.dash

var body: some View {
    TabView(selection: $selectedTab) {
        
        
        NavigationView {
            VStack {

                Text("Model Name")
                
                Form {
                    
                    Section {
                    Text("iOS") //Display iOSVer around here
                    Text("Details")
                    Text("Details")
                    Text("Details")
                    Text("Details")
                    Text("Details")
                    }
                    
                    Section {
                    Text("Details")
                    Text("Details")
                    }
                    
                }
                }
            .navigationTitle("Dashboard View")
        }

        .tabItem {
            Image(systemName: "iphone")
            Text("Dashboard")
        .tag(Tab.dash)
    }

1 Answer 1

2

You can do it this way

Text("iOS \(UIDevice.current.systemVersion)")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. Just to check, can this structure be used with variables? Text("Name (variable)")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.