Skip to content

Instantly share code, notes, and snippets.

eMdOS eMdOS

Block or report user

Report or block eMdOS

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eMdOS
eMdOS / UIApplication.swift
Created Aug 23, 2019
Topmost view controller
View UIApplication.swift
import UIKit
public extension UIApplication {
/// Returns the topmost view controller in the hierarchy of the given view controller.
///
/// If no parameter passed, by default the function takes the root view controller set for the key window in the application.
///
/// ```swift
/// UIApplication.shared.keyWindow?.rootViewController
/// ```
@eMdOS
eMdOS / Enum+Option.swift
Created Aug 23, 2019
Enum + Option -> Modern OptionSet
View Enum+Option.swift
// Playground
protocol Option: RawRepresentable, Hashable, CaseIterable {}
extension Set where Element: Option {
var rawValue: Int {
var rawValue = 0
for (index, element) in Element.allCases.enumerated() where contains(element) {
rawValue |= (1 << index)
}
@eMdOS
eMdOS / KeyedDecodingContainer.swift
Last active Aug 23, 2019
Decoding custom date formats using Decodable
View KeyedDecodingContainer.swift
extension KeyedDecodingContainer where Key: CodingKey {
func decodeDate(from key: Key, using formats: String...) throws -> Date {
let dateAsString = try decode(String.self, forKey: key)
let dateFormatter = DateFormatter()
for format in formats {
dateFormatter.dateFormat = format
guard let date = dateFormatter.date(from: dateAsString) else {
continue
}
return date
@eMdOS
eMdOS / app.md
Created Mar 12, 2019
Installing .app in iPhone simulator
View app.md

Installing .app in iPhone simulator

xcrun simctl install booted #{.app-path}

View DateFormatter+ISO8601.swift
// Swift 3
extension DateFormatter {
public static var iso8601: DateFormatter {
return DateFormatter.iso8601DateFormatter
}
private static let iso8601DateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
@eMdOS
eMdOS / gist:a5fa54a0e8be32dcd6b46b83824228e6
Created Feb 21, 2019 — forked from 480/gist:3b41f449686a089f34edb45d00672f28
MacOS X + oh my zsh + powerline fonts + visual studio code terminal settings
View gist:a5fa54a0e8be32dcd6b46b83824228e6
1. Install oh my zsh
http://ohmyz.sh/
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
1. Install powerline fonts
https://github.com/powerline/fonts
1. download agnoster theme
https://github.com/mbadolato/iTerm2-Color-Schemes/zipball/master
@eMdOS
eMdOS / ScrollableStackView.swift
Last active Jan 5, 2019
Scrollable Stack View
View ScrollableStackView.swift
import UIKit
public class ScrollableStackView: UIView {
// MARK: Properties
private var didSetupConstraints = false
private lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView(frame: .zero)
View Size Classes.md

Size Classes

(w, h)

iPad Pro 12.9"

Orientation Full Screen Split View 2/3 Split View 1/2 Split View 1/3
Portrait R, R C, R - C, R
@eMdOS
eMdOS / NibNameableView.swift
Created Nov 1, 2018
Table/Collection Views - Generic Cell Registration & Dequeuing
View NibNameableView.swift
import UIKit
public protocol NibNameableView: class {
static var nibName: String { get }
}
extension NibNameableView where Self: UIView {
public static var nibName: String {
return String(describing: self)
}
View ResultType.swift
import Foundation
public enum ResultType<Value> {
case success(Value)
case failure(Swift.Error)
}
extension ResultType {
public init(value: () throws -> Value) {
do {
You can’t perform that action at this time.