Skip to content

Instantly share code, notes, and snippets.

View arashkashi's full-sized avatar
💭
Working with machines against the machine

A.K. arashkashi

💭
Working with machines against the machine
View GitHub Profile
enum JSONDecodingError: Error {
case decodingError(DecodingError)
case unknown
}
extension DecodingError {
var stringValue: String {
switch self {
case .valueNotFound(let value, let context):
return "Value '\(value)' not found:" + context.debugDescription + "codingPath:" + context.codingPath.map { $0.stringValue }.joined(by: "<->")
@arashkashi
arashkashi / injection.swift
Created November 21, 2022 15:46
a light weight injection code.
// MARK: Demontration of Usage of Injection system
// 1. First step: make the key object, the current value type is the one you are trying to add to injection system.
private struct BaseClassKey: InjectionKey {
static var currentValue: BaseClass = RealSubClass()
}
// 2. How to inject the currect value
func test() {
var dataController = TestDataStructure()
@arashkashi
arashkashi / AppCoreDataManager.swift
Created November 7, 2022 07:33 — forked from levibostian/AppCoreDataManager.swift
iOS CoreData ultimate document. Stack, tutorial, errors could encounter. All my CoreData experience for what works in 1 document.
import CoreData
import Foundation
protocol CoreDataManager {
var uiContext: NSManagedObjectContext { get }
func newBackgroundContext() -> NSManagedObjectContext
func performBackgroundTaskOnUI(_ block: @escaping (NSManagedObjectContext) -> Void)
func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -> Void)
func loadStore(completionHandler: ((Error?) -> Void)?)
}
//
// BMW Motorrad Connected App for iOS
//
// Copyright © 2022 BMW Group. All rights reserved.
//
import Foundation
import SwiftUI
import WidgetKit
struct WidgetSmallView: View {
@arashkashi
arashkashi / combine_retry.swift
Last active August 16, 2022 10:25
how to make a retry function on swift combine
import SwiftUI
import Combine
struct ContentView: View {
class ViewModel: ObservableObject {
var bag = Set<AnyCancellable>()
init() {
fetchFeeds()
.tryCatch({ err -> AnyPublisher<Int, Error> in
enum TintFont {
enum TypeFace {
case bold
case boldItalic
case book
case bookItalic
case medium
case mediumItalic
@arashkashi
arashkashi / multiple_fetching.swift
Last active January 19, 2023 08:42
multiple BE calls for fetching data
class ViewModel: ObservableObject {
var bag = Set<AnyCancellable>()
var t = "hellow"
init() {
let mainPublisher = [3, 2, 1].publisher
mainPublisher.flatMap({ value in
printit(value).map { calcualted in
return (value, calcualted)
}
})
@arashkashi
arashkashi / flowlayout.swift
Last active July 6, 2021 17:16
layout horizontally with new line instead of wrapping.
struct SizeArrayKey: PreferenceKey {
static var defaultValue: [CGSize] = []
static func reduce(value: inout Value, nextValue: () -> Value ) {
value.append(contentsOf: nextValue())
}
}
struct Item: Identifiable {
var id = UUID()
@arashkashi
arashkashi / customRoundedCorder.swift
Created June 11, 2021 07:34
decide which sides of a rectangle you would like to be rounded #swiftui
//
// ContentView.swift
// testswiftUI
//
// Created by Arash on 2021-06-10.
//
import SwiftUI
struct ContentView: View {
@arashkashi
arashkashi / gradientSlider.swift
Created June 11, 2021 06:57
experiment how start and end point affect gradient
//
// ContentView.swift
// testswiftUI
//
// Created by Arash on 2021-06-10.
//
import SwiftUI
struct ContentView: View {