Mobile App Development 2021W Lecture 16: Difference between revisions

From Soma-notes
Created page with "==iOS TapDemo== ===ContentView.swift=== <syntaxhighlight lang="swift" line> // // ContentView.swift // Shared // // Created by Anil Somayaji on 2021-03-15. // import Swi..."
 
No edit summary
Line 1: Line 1:
==iOS TapDemo==
==Code==


===ContentView.swift===
===TapDemo/Shared/ContentView.swift===


<syntaxhighlight lang="swift" line>
<syntaxhighlight lang="swift" line>

Revision as of 17:27, 15 March 2021

Code

TapDemo/Shared/ContentView.swift

//
//  ContentView.swift
//  Shared
//
//  Created by Anil Somayaji on 2021-03-15.
//

import SwiftUI

struct ContentView: View {
    @State var count = 0
    var body: some View {
        VStack{
            Button("Tap here!", action: onTapped)
                .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
            
            Text("You have tapped \(count) times.")
            .padding()
        }
    }
    func onTapped() {
        count = count + 1
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}