Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
//
// ViewModelTests.swift
// UnitTestingTests
//
// Created by Maksim Vialykh on 7/17/21.
//
import XCTest
@testable
import UnitTesting
//
// ViewModel.swift
// UnitTesting
//
// Created by Maksim Vialykh on 7/17/21.
//
import Foundation
protocol ViewModel: AnyObject {
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
typealias EmptyClosure = () -> Void
class ActionableTextField: UITextField {
private var cancelAction: EmptyClosure?
import UIKit
import PlaygroundSupport
// API CLient
typealias Resource = (url: String, method: String, data: Data)
class APIClient {
func request(_ res: Resource, _ result: @escaping (Result<Data, Error>) -> Void) {
/*
All network code
import UIKit
import PlaygroundSupport
let url = URL(string: "https://petstore.swagger.io/v2/user")!
var request = URLRequest(url: url)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "accept")
request.httpMethod = "POST"
request.httpBody = """
{
import UIKit
class ViewController: UIViewController {
/*
Current active (firstRespounder) textField
*/
private weak var activeTextField: UITextField?
/*
local intance of KeyboardObserver
import UIKit
class KeyboardObserver {
/*
KeyboardState provides two states
- hide when kyboard is hidden
- show(let kyboardHeight) when keyboard is shown
*/
enum KeyboardState {
....
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Get the managed object context from the shared persistent container.
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
import SwiftUI
struct ContentView: View {
@EnvironmentObject
var viewModel: ViewModel
var body: some View {
VStack {
Spacer()
import Foundation
import LocalAuthentication
class ViewModel: ObservableObject {
@Published
var loggedIn: Bool = false
@Published
var hasChanges: Bool = false