Difference between revisions of "Mobile App Development 2021W Lecture 16"

From Soma-notes
Jump to navigation Jump to search
(Created page with "==iOS TapDemo== ===ContentView.swift=== <syntaxhighlight lang="swift" line> // // ContentView.swift // Shared // // Created by Anil Somayaji on 2021-03-15. // import Swi...")
 
Line 1: Line 1:
==iOS TapDemo==
==Code==


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


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

Revision as of 13: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()
    }
}