Search code examples
iosswiftuiios14

Show some view, only if iOS 14, SwiftUI


I want to show a Text view say:

Text("Welcome to iOS 14")

if the user is using iOS 14.

If the user is using other iOS versions I Want to show a different Text view, say:

Text("Welcome to Different iOS version") 

How can I achieve that?


Solution

  • struct ContentView: View {
        
        var systemVersion = UIDevice.current.systemVersion
    
        var body: some View {
            if systemVersion.starts(with: "14" ) {
                Text("welcome to ios 14")
            } else {
                Text("Welcome to Different iOS version")
            }
            
        }
    }