Skip to content

Instantly share code, notes, and snippets.

@niazoff
niazoff / CombineBasics.swift
Created January 2, 2020 14:18
Introduction to Combine using Instagram analogy
import Foundation
import Combine
struct Post {
let imageName: String
let description: String?
init(imageName: String, description: String? = nil) {
self.imageName = imageName
self.description = description
@niazoff
niazoff / Int+HebrewNumeral.swift
Created July 15, 2019 19:15
Hebrew Numerals in Swift
import Foundation
extension Int {
/// Returns the Hebrew numeral represented by the receiver's value.
///
/// Example: A value of 1 retuns א׳.
/// A value of 0 or any value above one million returns the value in regular Arabic numerals.
func toHebrewNumeral() -> String {
let absoluteSelf = abs(self)
// `DateFormatter` won't use Hebrew numerals after a million so simply return self.
@niazoff
niazoff / Storyboardable.swift
Created October 9, 2018 01:05
A protocol for creating a view controller from a storyboard with the same name faster.
/// A `UIViewController` that has a matching storyboard file with the same name.
protocol Storyboardable where Self: UIViewController {}
extension Storyboardable {
/// Returns a `UIViewController` instance with the initial view controller of the matching storyboard file in the given bundle.
static func storyboardInstance(bundle: Bundle = Bundle.main) -> Self {
let className = String(describing: Self.self)
let storyboard = UIStoryboard(name: className, bundle: bundle)
if let initialViewController = storyboard.instantiateInitialViewController() as? Self {
return initialViewController