This file contains 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 Froggy: ViewModifier { | |
func body(content: Content) -> some View { | |
content | |
.font(.custom("Times New Roman", size: 32)) | |
.foregroundColor(.green) | |
.bold() |
This file contains 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 | |
func Haiku() -> String { | |
"Furu ike ya kawazu tobikomu mizu no oto" | |
/* | |
"Furu ike ya" | |
"kawazu tobikomu" | |
"mizu no oto" |
This file contains 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 { | |
let _ = print("hello") | |
This file contains 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 Music { | |
var title = "Ninth Symphony" | |
var composer = "Beethoven" | |
var playlist = "Classical" | |
} |
This file contains 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 | |
@propertyWrapper | |
struct SimpleState<T>: DynamicProperty { | |
private var _state: State<T> // references SwiftUI memory outside of struct | |
var wrappedValue: T { | |
get { _state.wrappedValue } // accesses reference to SwiftUI memory | |
nonmutating set { _state.wrappedValue = newValue } // no change to reference |
This file contains 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 // for subscription | |
final class HeapStore<T> { | |
var value: T | |
init(initValue: T) { | |
value = initValue |
This file contains 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 | |
@main | |
struct StateValueApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
.environment(A(1)) |
This file contains 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 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 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 = "counter" | |
func inc() { count += 1 } |
NewerOlder