Skip to content

Instantly share code, notes, and snippets.

View hasanalisiseci's full-sized avatar
🏠
Working from home!

Hasan Ali hasanalisiseci

🏠
Working from home!
View GitHub Profile
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 {
struct WeatherVMKey: EnvironmentKey {
static var defaultValue = WeatherViewModel()
}
extension EnvironmentValues {
var weatherVM: WeatherViewModel {
get { self[WeatherVMKey.self] }
set { self[WeatherVMKey.self] = newValue }
}
}
@Observable
class WeatherViewModel {
...
}
struct WeatherView: View {
@State var weatherVM = WeatherViewModel()
var body: some View {
...
@Observable
class WeatherViewModel {
var currentTemperature: Double = -5.2
var city: String = "Sivas"
var isSnowing: Bool = false
@ObservationIgnored var isRaining = false
}
@main
struct ObservableDemoApp: App {
// 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
@hasanalisiseci
hasanalisiseci / HalfSheetWithUIKitForSwiftUI.swift
Created December 23, 2023 11:02
Half Sheet with UIKit for SwiftUI
//
// HalfSheetWithUIKitForSwiftUI.swift
// TestAppForNewThinks
//
// Created by Hasan Ali Şişeci on 23.12.2023.
//
import SwiftUI
extension View {
import SwiftUI
import LinearBGPackageDemo
struct DemoContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
}.linearGradientBackground()
}
}
//
// LinearGradientBG.swift
//
//
// Created by Hasan Ali Şişeci on 13.12.2023.
//
import SwiftUI
public struct LinearGradientBackground: ViewModifier {
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")
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