Skip to content

Instantly share code, notes, and snippets.

View ANSCoder's full-sized avatar
🎯
Focusing

Anand Nimje ANSCoder

🎯
Focusing
View GitHub Profile
@ANSCoder
ANSCoder / MainActorForClass.swift
Last active February 24, 2024 08:12
MainActor for ViewModel class
@MainActor
class UserViewModel: ObservableObject {
@Published private(set) var userDetails = UserDetails()
func loadUserDetails() {
Task {
do {
userDetails = try await fetchUserData()
} catch {
showError(error)
@ANSCoder
ANSCoder / MainActorExample.swift
Last active February 24, 2024 08:12
MainActor in SwiftUI
class UserViewModel: ObservableObject {
@Published private(set) var userDetails = UserDetails()
func loadUserDetails() {
Task {
do {
userDetails = try await fetchUserData()
} catch {
showError(error)
}
@ANSCoder
ANSCoder / LazyView.swift
Created August 22, 2021 14:29
Solution for Create Controller inside NavigationButton lazily in SwiftUI.
//
// LazyView.swift
// Grocers
//
// Created by Anand Nimje on 10/09/20.
// Copyright © 2020 Anscoder. All rights reserved.
//
import SwiftUI
@ANSCoder
ANSCoder / UnwrapUtil.swift
Created August 22, 2021 14:21
Unwrap values inside the SwiftUI `View`
//
// UnwrapUtil.swift
// Grocers
//
// Created by Anand Nimje on 08/09/20.
// Copyright © 2020 Anscoder. All rights reserved.
//
import SwiftUI
@ANSCoder
ANSCoder / GridStack.swift
Created August 22, 2021 14:14
Grid View in SwiftUI (iOS - 13)
//
// GridStack.swift
// Grocers
//
// Created by Anand Nimje on 27/08/20.
// Copyright © 2020 Anscoder. All rights reserved.
//
import SwiftUI
@ANSCoder
ANSCoder / FileUtility.swift
Last active November 1, 2022 05:24
Read and Write Codable Models from the JSON file inside FileManager. 🎉
//
// FileUtility.swift
// TravelApp
//
// Created by Anand Nimje on 13/04/20.
// Copyright © 2020 Anand. All rights reserved.
//
import Foundation
@ANSCoder
ANSCoder / Propertywrapper.swift
Last active May 6, 2020 20:56
Propertywrapper for UserDefaults in Swift
private protocol AnyOptional{
var isNil: Bool { get }
}
extension Optional: AnyOptional{
var isNil: Bool { self == nil }
}
@propertyWrapper
@ANSCoder
ANSCoder / MVVM with Boxing in Swift 4.2
Created March 10, 2019 16:22
Boxing in Swift 4.2
class Box<T>{
typealias Listener = (T) -> Void
var listener: Listener?
var value: T {
didSet{
listener?(value)
}
}
func asyncWork(){
let northZone = DispatchQueue(label: "perform_task_with_team_north")
let southZone = DispatchQueue(label: "perform_task_with_team_south")
northZone.async {
for numer in 1...3{ print("North \(numer)") }
}
southZone.async {
for numer in 1...3{ print("South \(numer)") }
}
func syncWork(){
let northZone = DispatchQueue(label: "perform_task_with_team_north")
let southZone = DispatchQueue(label: "perform_task_with_team_south")
northZone.sync {
for numer in 1...3{ print("North \(numer)")}
}
southZone.sync {
for numer in 1...3{ print("South \(numer)") }
}