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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>API_KEY</key> | |
<string>123456789</string> | |
</dict> | |
</plist> |
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
struct ContentView: View { | |
private let viewModel = HobbyViewModel() | |
@State private var showAlert: Bool = false | |
@State private var randomHobby: Hobby? | |
var body: some View { | |
Button("Random hobby") { | |
randomHobby = viewModel.randomHobby() |
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
struct ContentView: View { | |
@State private var showAlert: Bool = false | |
var body: some View { | |
Button("Show alert") { | |
showAlert = true | |
}.alert( | |
"Hello!", | |
isPresented: $showAlert, |
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
struct ContentView: View { | |
@State private var showAlert: Bool = false | |
var body: some View { | |
Button("Show alert") { | |
showAlert = true | |
}.alert("Hello!", isPresented: $showAlert, actions: {}) | |
} | |
} |
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
struct ContentView: View { | |
@State private var showAlert: Bool = false | |
var body: some View { | |
Button("Show alert") { | |
showAlert = true | |
} | |
} | |
} |
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
struct ContentView: View { | |
@State private var showAlert: Bool = false | |
// ... | |
} |
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
@Observable | |
class ChatViewModel { | |
// ... | |
var scrollPosition: UUID? = nil | |
func sendMessage() { | |
guard canSendMessage else { return } | |
// In a real chat app this would make a server call to send the message | |
let message = Message(role: .sender, text: draftMessage) |
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
SendMessageButton { | |
viewModel.sendMessage() | |
} | |
.disabled(!viewModel.canSendMessage) |
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
struct ChatView: View { | |
@Bindable private var viewModel: ChatViewModel = ChatViewModel() | |
var body: some View { | |
NavigationStack { | |
VStack { | |
ChatMessagesList(viewModel: viewModel) | |
HStack { | |
MessageTextField(draftMessage: $viewModel.draftMessage) |
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
import SwiftUI | |
struct ChatMessagesList: View { | |
@Bindable var viewModel: ChatViewModel | |
var body: some View { | |
ScrollView { | |
ForEach(viewModel.messages) { message in | |
MessageCell(message: message) |
NewerOlder