Skip to content

Instantly share code, notes, and snippets.

View reyandrey's full-sized avatar

Andrey Fokin reyandrey

  • Saint Petersburg, Russia
View GitHub Profile
@reyandrey
reyandrey / MacEditorTextView.swift
Created September 26, 2020 03:17 — forked from unnamedd/MacEditorTextView.swift
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@reyandrey
reyandrey / HTTP.swift
Last active September 9, 2020 21:54
HTTP client with Codable support
//
// HTTP.swift
//
// Created by Andrey Fokin on 08.09.2020.
// Copyright © 2020 Andrey Fokin. All rights reserved.
//
import Foundation
import Security
@reyandrey
reyandrey / Solution.swift
Created August 12, 2020 21:13
Another task
import Foundation
/*
(())()
(()
)((())
*/
func isValid(_ str: String) -> Bool {
var count = 0
import Foundation
import os.log
public class Log<T> {
private let log: OSLog
public init(){
self.log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "unknown", category: String(describing: T.self))
}
@reyandrey
reyandrey / Coordinator.swift
Last active June 20, 2020 14:29
Coordinator default implementation
protocol CoordinatorProtocol: class {
var completionHandler: (()->())? { get set }
var childCoordinators: [CoordinatorProtocol] { get set }
func start()
}
extension CoordinatorProtocol {
func addChild(_ coordinator: CoordinatorProtocol) {
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
guard tableView.isDragging else { return }
cell.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 0.3, animations: {
cell.transform = CGAffineTransform.identity
})
}
@reyandrey
reyandrey / decode-json-swift.swift
Created March 23, 2020 20:41 — forked from mikebuss/decode-json-swift.swift
Decode [Any] and [String: Any] Swift 4
//
//
// Adapted from:
//
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
// Adds encoding: https://github.com/3D4Medical/glTFSceneKit/blob/master/Sources/glTFSceneKit/GLTF/JSONCodingKeys.swift
// Adds fix for null inside arrays causing infinite loop: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24#gistcomment-2807855
//
struct JSONCodingKeys: CodingKey {
var stringValue: String
@reyandrey
reyandrey / UserDefaultsStorage.swift
Created March 22, 2020 05:49
UserDefaults property wrapper example
import UIKit
import Foundation
/// Обертка, которая позволи хранить переменные сразу в UserDefaults
@propertyWrapper public struct UserDefaultsStandart<T> {
/// Ключи
public enum Key: String {
case foo
@reyandrey
reyandrey / CoreDataStack.swift
Last active August 20, 2020 12:59
Core Data stack
import Foundation
import CoreData
public class CoreDataStack {
//MARK: Constants
let kBundleId = "com.qwe.rty.uiop"
let kModelName = "model"
@reyandrey
reyandrey / gist:b678d28669a3575fea2b8a03567e70fc
Created August 5, 2019 09:21
NSCoder extension for CodingKey
extension NSCoder {
func encode(_ object: Any?, forKey key: CodingKey) {
encode(object, forKey: key.stringValue)
}
}