Skip to content

Instantly share code, notes, and snippets.

View eMdOS's full-sized avatar

Emilio Ojeda eMdOS

  • Zapopan, Jalisco
View GitHub Profile
@eMdOS
eMdOS / NibNameableView.swift
Created November 1, 2018 14:21
Table/Collection Views - Generic Cell Registration & Dequeuing
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)
}
@eMdOS
eMdOS / Size Classes.md
Created November 10, 2018 03:20
Size Classes

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 / ScrollableStackView.swift
Last active November 24, 2024 02:13
Scrollable Stack View
import UIKit
public class ScrollableStackView: UIView {
// MARK: Properties
private var didSetupConstraints = false
private lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView(frame: .zero)
@eMdOS
eMdOS / gist:a5fa54a0e8be32dcd6b46b83824228e6
Created February 21, 2019 03:22 — forked from 480/gist:3b41f449686a089f34edb45d00672f28
MacOS X + oh my zsh + powerline fonts + visual studio code terminal settings
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
// 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 / app.md
Created March 12, 2019 16:34
Installing .app in iPhone simulator

Installing .app in iPhone simulator

xcrun simctl install booted #{.app-path}

@eMdOS
eMdOS / KeyedDecodingContainer.swift
Last active August 23, 2019 23:15
Decoding custom date formats using Decodable
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 / Enum+Option.swift
Created August 23, 2019 21:10
Enum + Option -> Modern OptionSet
// 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 / UIApplication.swift
Created August 23, 2019 23:11
Topmost view controller
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 / combine example.swift
Created May 1, 2020 23:29
Medium: Extending the Swift's Result type
let url: URL = "https://api.themoviedb.org/3/movie/now_playing?api_key=\(apiKey)&page=1"
URLSession.shared
.dataTaskPublisher(for: url)
.map(\.data)
.decode(type: MoviesPage.self, decoder: JSONDecoder())