Skip to content

Instantly share code, notes, and snippets.

extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
@pranjalsatija
pranjalsatija / ReusableTableViewCell.swift
Created February 8, 2020 00:31
A reusable table view cell. Storyboard not included.
import UIKit
class ReusableTableViewCell: UITableViewCell {
static let identifier = String(describing: ReusableTableViewCell.self)
var leading: UIView? {
didSet {
if let oldValue = oldValue {
stackView.removeArrangedSubview(oldValue)
}
@pranjalsatija
pranjalsatija / IdentifiableCell.swift
Last active March 29, 2020 07:59
An example of how to make dequeuing and instantiating UITableViewCells a little nicer.
protocol IdentifiableCell {
static var identifier: String { get }
}
extension IdentifiableCell {
static var identifier: String { String(describing: Self.self) }
}
extension IdentifiableCell where Self: UITableViewCell {
static func dequeue(in tableView: UITableView) -> Self {
@atereshkov
atereshkov / swift-5-resumable-timer.swift
Created August 19, 2019 14:39
Swift 5 Resumable Timer
class ResumableTimer: NSObject {
private var timer: Timer? = Timer()
private var callback: () -> Void
private var startTime: TimeInterval?
private var elapsedTime: TimeInterval?
// MARK: Init
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@ArtFeel
ArtFeel / CALayer+AnimationPlayback.swift
Last active November 15, 2023 23:06
Persistent Core Animations (Swift 4.2). All you need is `self.layer.makeAnimationsPersistent()` 😎
//
// CALayer+AnimationPlayback.swift
// Created by Philip Vasilchenko on 4/27/18.
//
import UIKit
// Pause animations of layer tree
//
// Technical Q&A QA1673: