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 / ScrollableStackView.swift
Last active November 18, 2023 03:20
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 / doc.md
Created January 10, 2018 22:54
[Swift] URL: ExpressibleByStringLiteral

Extension:

extension URL: ExpressibleByStringLiteral {
    public init(stringLiteral value: StaticString) {
        guard let url = URL(string: "\(value)") else {
            fatalError("Invalid URL string literal: \(value)")
        }
        self = url
 }
@eMdOS
eMdOS / NibLoadableView.swift
Last active October 15, 2021 12:29
Reusable views and cell registration and dequeuing (for table views and collection views)
protocol NibLoadableView: class {
static var nibName: String { get }
}
extension NibLoadableView where Self: UIView {
static var nibName: String {
return String(describing: self)
}
}
@eMdOS
eMdOS / HowTo use xcconfig or plist with SPM.md
Created November 9, 2020 21:13 — forked from 4np/HowTo use xcconfig or plist with SPM.md
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
let elements: [String] = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
let chunk_1 = elements[...2].joined()
let chunk_2 = elements[3...5].joined()
let chunk_3 = elements[6...].joined()
concat(elements) == chunk_1 <> chunk_2 <> chunk_3
concat(elements) == concat([chunk_1, chunk_2, chunk_3])
concat(["A", "B", "C"]) == [String](arrayLiteral: "A", "B", "C").reduce("", <>)
public func concat<M: Monoid>(_ elements: [M]) -> M {
elements.reduce(.empty, <>)
}
extension String: Monoid {
public static let empty: String = ""
}
extension Array: Monoid {
public static var empty: Array { [] }
}
// left identity
[] + ["A"] // = ["A"]
// right identity
["A"] + [] // = ["A"]
// left identity
"" + "A" // = "A"
// right identity
"A" + "" // = "A"