Skip to content

Instantly share code, notes, and snippets.

View ramzesenok's full-sized avatar
:octocat:

Roman Mirzoyan ramzesenok

:octocat:
View GitHub Profile
@ramzesenok
ramzesenok / UIKit-SwiftUI-Coordinator.swift
Last active October 18, 2022 17:10
An approach to use SwiftUI views inside UIKit Coordinator
class Coordinator: UINavigationController {
init() {
super.init(nibName: nil, bundle: nil)
let firstVC = HostingController { FirstView(push: push) }
setViewControllers([firstVC], animated: false)
}
required init?(coder aDecoder: NSCoder) {
@ramzesenok
ramzesenok / CustomSwipeActions.swift
Created March 20, 2022 17:19
SwiftUI custom swipe actions cause there are none outside of the List
struct ContentView: View {
@State var titles = ["Cell #1", "Cell #2", "Cell #3", "Cell #4"]
var body: some View {
NavigationView {
ScrollView {
VStack(spacing: 0) {
ForEach(self.titles, id: \.self) { title in
HStack {
Text(title)
@ramzesenok
ramzesenok / TabViewPickerBinding.swift
Created January 25, 2022 17:34
An example of a view with a segmented picker and a paginated tab view that are bound to each other
enum Page: Identifiable, CaseIterable {
case first, second
var title: String {
switch self {
case .first:
return "First"
case .second:
return "Second"
}
@ramzesenok
ramzesenok / CoreDataViewModelArchitecture.swift
Last active May 12, 2022 06:26
My attempt to build a reusable ViewModel that uses CoreData as its persistence store
import Combine
import SwiftUI
import CoreData
class CoreDataViewModel: NSObject, ObservableObject, NSFetchedResultsControllerDelegate {
let container: NSPersistentContainer
private var controllerUpdates = [NSObject: CurrentValueSubject<[NSFetchRequestResult], Never>]()
init(container: NSPersistentContainer) {
self.container = container
@ramzesenok
ramzesenok / calc.swift
Last active October 17, 2021 10:42
Here's my attempt to create a calculator, that takes a string as an input, parses it and calculates the result. Key difficulties: taking the operator's precedence and parenthesis in account. Operates only on integer values. Solved using an AST
// MARK: - Data Structures
enum Operation: String {
case add = "+"
case subtract = "-"
case multiply = "*"
case divide = "/"
var action: (Int, Int) -> Int {
switch self {