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
| struct WeatherView: View { | |
| @State var weatherVM = WeatherViewModel() | |
| var body: some body { | |
| SubWeatherView(vm: weatherVM) | |
| } | |
| } | |
| struct SubWeatherView:View { | |
| @Bindable var vm: WeatherViewModel | |
| var body: some body { |
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
| struct WeatherVMKey: EnvironmentKey { | |
| static var defaultValue = WeatherViewModel() | |
| } | |
| extension EnvironmentValues { | |
| var weatherVM: WeatherViewModel { | |
| get { self[WeatherVMKey.self] } | |
| set { self[WeatherVMKey.self] = newValue } | |
| } | |
| } |
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
| @Observable | |
| class WeatherViewModel { | |
| ... | |
| } | |
| struct WeatherView: View { | |
| @State var weatherVM = WeatherViewModel() | |
| var body: some View { | |
| ... |
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
| @Observable | |
| class WeatherViewModel { | |
| var currentTemperature: Double = -5.2 | |
| var city: String = "Sivas" | |
| var isSnowing: Bool = false | |
| @ObservationIgnored var isRaining = false | |
| } | |
| @main | |
| struct ObservableDemoApp: App { |
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
| // MARK: Old Observable Class | |
| class WeatherViewModel: ObservableObject { | |
| @Published var currentTemperature: Double = -5.2 | |
| @Published var city: String = "Sivas" | |
| @Published var isSnowing: Bool = false | |
| } | |
| // MARK: New Observable Class | |
| @Observable class WeatherViewModel { | |
| var currentTemperature: Double = -5.2 |
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
| // | |
| // HalfSheetWithUIKitForSwiftUI.swift | |
| // TestAppForNewThinks | |
| // | |
| // Created by Hasan Ali Şişeci on 23.12.2023. | |
| // | |
| import SwiftUI | |
| extension View { |
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
| import SwiftUI | |
| import LinearBGPackageDemo | |
| struct DemoContentView: View { | |
| var body: some View { | |
| VStack { | |
| Text("Hello, world!") | |
| }.linearGradientBackground() | |
| } | |
| } |
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
| // | |
| // LinearGradientBG.swift | |
| // | |
| // | |
| // Created by Hasan Ali Şişeci on 13.12.2023. | |
| // | |
| import SwiftUI | |
| public struct LinearGradientBackground: ViewModifier { |
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
| struct QuickActionsView: View { | |
| @State var navigationValue: Int? = nil | |
| @StateObject var qaManager = QuickActionsManager.instance | |
| @Environment(\.scenePhase) var phase | |
| var body: some View { | |
| VStack { | |
| Text("Quick Actions").font(.largeTitle).bold() | |
| NavigationLink(tag: 1, selection: $navigationValue) { | |
| Text("Search QA") |
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
| class QuickActionsManager: ObservableObject { | |
| static let instance = QuickActionsManager() | |
| @Published var quickAction: QuickAction? = nil | |
| func handleQaItem(_ item: UIApplicationShortcutItem) { | |
| print(item) | |
| if item.type == "SearchAction" { | |
| quickAction = .search | |
| } else if item.type == "Home" { | |
| quickAction = .home |
NewerOlder