Skip to content

Instantly share code, notes, and snippets.

@kvaDrug
kvaDrug / Minimalistic (iOS).joboptions
Created September 10, 2019 08:42
Adobe Illustrator preset for exporting lightweight PDF files intended for use with Xcode as vector icons. Put it to /Users/Username/Library/Application Support/Adobe/Adobe PDF/Settings.
<<
/ASCII85EncodePages false
/AllowPSXObjects false
/AllowTransparency true
/AlwaysEmbed [
true
]
/AntiAliasColorImages false
/AntiAliasGrayImages false
/AntiAliasMonoImages false
@kvaDrug
kvaDrug / JSONHelpers.swift
Created February 20, 2019 21:47
A robust way to create JSON objects from JSONSerialization.
//
// Created by Vladimir Kelin on 2/8/19.
// Copyright © 2019 Systematix Infotech. All rights reserved.
//
/*
A more robust way to create JSON objects from JSONSerialization.
Why more robust? See the explanation:
http://kelindev.blogspot.com/2018/01/safer-parsing-with-jsonserialization-in.html
*/
@kvaDrug
kvaDrug / Unwrap.swift
Created February 20, 2019 21:43
Unwraps an optional and throws error if nil. The related blogpost: https://kelindev.blogspot.com/2018/01/catching-nil-as-error.html.
func unwrap<T>(_ optional: T?) throws -> T {
if let real = optional {
return real
} else {
throw UnwrapError(optional: optional)
}
}
struct UnwrapError<T>: Error, CustomStringConvertible {
let optional: T?
@kvaDrug
kvaDrug / StoryboardInstantiatableViewController.swift
Created February 20, 2019 21:37
A Swift protocol allowing to 1) shorten the code required to instantiate an UIViewController from a storyboard 2) store the storyboard id in the predictable place
import UIKit
/**
This protocol along with the extension provides some syntactic sugar and solves two common problems:
- Shortens the instantiation
- Answers, where to store the storyboard id
Blog post: https://kelindev.blogspot.com/2018/10/uikit-protocol-of-month.html
*/
protocol StoryboardInstantiatableViewController {
static var storyboardId: String { get }