Skip to content

Instantly share code, notes, and snippets.

View CBeloch's full-sized avatar

Christopher Beloch CBeloch

View GitHub Profile
import Foundation
extension Character {
var isEmoji: Bool {
return unicodeScalars.allSatisfy { $0.properties.isEmoji }
}
}
func recentlyUsedEmoji() -> [Character]? {
#if os(iOS)
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@jordansinger
jordansinger / iPod.swift
Created July 27, 2020 21:19
Swift Playgrounds iPod Classic
import SwiftUI
import PlaygroundSupport
struct iPod: View {
var body: some View {
VStack(spacing: 40) {
Screen()
ClickWheel()
Spacer()
}
extension Result {
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> {
flatMapError { _ in
.init { try handler() }
}
}
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> {
flatMapError { error in
.init { try handler(error) }
@phranck
phranck / PlatformVisibility.swift
Last active November 13, 2022 22:40
A Swift view modifier to handle visibility of views for specific platforms
import SwiftUI
public struct Platform: OptionSet {
public var rawValue: UInt8
public static let iOS = Platform(rawValue: 1 << 0)
public static let macOS = Platform(rawValue: 1 << 1)
public static let tvOS = Platform(rawValue: 1 << 2)
public static let watchOS = Platform(rawValue: 1 << 3)
public static let all: Platform = [.iOS, .macOS, .tvOS, .watchOS]