Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
@jeksys
jeksys / Example.swift
Created July 8, 2021 05:25 — forked from VAnsimov/HostingView Example.swift
SwiftUI View to UIView
import UIKit
import SwiftUI
// SwiftUI
struct SomeView: View, HostingViewInitialization {
var body: some View {
Text("Hello World!")
}
}
import UIKit
import WebKit
class WebViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
private let url: URL
init(title: String, url: URL) {
self.url = url
protocol Storable {
func get<T: Codable>(key: String) -> T?
func remove(for key: String)
func add<T: Codable>(object: T, key: String)
func update<T: Codable>(object: T, key: String)
}
class UserDefaultsStorage: Storable {
static let shared = UserDefaultsStorage()
#if DEBUG
setDebugLevel(level: .debug, for: .generic)
setDebugLevel(level: .info, for: .network)
#endif
func setDebugLevel(level: DebugLevel?, for space: DebugSpace) {
#if DEBUG
LogManager.shared.debugLevel[space] = level
#endif
}
@jeksys
jeksys / gist:6e6f827dba480ca2ed49662a9aefeab4
Created February 24, 2020 22:20
Salaries in Vancouver,BC, Canada vs Seattle, WA,US
Vancouver: Salary: 90,000 Total Taxes: 22,278
Seattle: 90,000, Total Taxes: 19,860, Medical insurance: $500 X 12
https://smartasset.com/taxes/income-taxes#Kha75LrjSO
https://simpletax.ca/calculator
@jeksys
jeksys / Thread-Safe.md
Last active January 18, 2024 07:49
Thread-Safe Arrays in Swift

What's concurrency

Concurrency means running more than one task at the same time.

What is a race condition?

When you have two threads changing a variable simultaneously. It’s possible to get unexpected results. Imagine a bank account where one thread is subtracting a value to the total and the other is adding a value.

What's thread safe in Swift

Nothing in Swift is intrinsically threadsafe

class ImageScalerTests: XCTestCase {
func testScalingProducesSameAmountOfImages() {
let scaler = ImageScaler()
let originalImages = loadImages()
// Create an expectation
let expectation = self.expectation(description: "Scaling")
var scaledImages: [UIImage]?
scaler.scale(originalImages) {
import Foundation
extension CustomStringConvertible {
var description: String {
var description: String = "\(type(of: self))("
let selfMirror = Mirror(reflecting: self)
for child in selfMirror.children {
if let propertyName = child.label {
@jeksys
jeksys / gist:4d63224f6b6d8f5c9ca1b8d1500afcb6
Created July 3, 2019 01:30
Pod set pod name to a specific pod version
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['Pod name'].include? target.name
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
end
end
end
end
@jeksys
jeksys / ViewControllerWillAppear.swift
Created June 13, 2019 18:30
Source of view appear calls
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
print("isMovingToParent")
// this view controller is becoming visible because it was just push onto a navigation controller or some other container view controller
} else if isBeingPresented {
print("isBeingPresented")
// this view controller is becoming visible because it is being presented from another view controller
} else if view.window == nil {