This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
import UIKit | |
final class MainView: UIView { | |
var counter: UILabel! | |
private var addOne: UIButton! | |
required init?(coder: NSCoder) { | |
fatalError("MainView: does not support unarchiving view from xib/nib files") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
class MainView(context: Context): ConstraintLayout(context) { | |
val counter: TextView | |
val addOne: Button | |
init { | |
counter = TextView(context).apply { | |
textSize = 44.0f | |
id = generateViewId() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
var count by remember { mutableStateOf(0) } | |
Column(horizontalAlignment = Alignment.CenterHorizontally, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
import SwiftUI | |
struct ContentView: View { | |
@State var count = 0 | |
var body: some View { | |
VStack { | |
Text("\(count)") | |
Button("+1", action: { count += 1 } ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS Reactive | |
import SwiftUI | |
struct ChildView: View { | |
let count: Int // new state if @State | |
var body: some View { | |
Text("\(count)") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS Reactive | |
import SwiftUI | |
struct ChildView: View { | |
@Binding var count: Int | |
var body: some View { | |
Button("+1") { count += 1 } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
import SwiftUI | |
import Observation | |
@Observable | |
final class RefCounter { | |
var count = 0 | |
//@ObservationIgnored | |
var name = "even" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
import SwiftUI | |
import Observation | |
@Observable | |
final class RefCounter { | |
var count = 0 | |
var name = "counter" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS 441 | |
import SwiftUI | |
import Observation | |
@Observable | |
final class RefCounter { | |
var count = 0 | |
var name = "counter" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UM EECS Reactive | |
import SwiftUI | |
@main | |
struct StateValueApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
// #1: comment out for optional |
OlderNewer