Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
chriseidhof / ContentView.swift
Last active May 9, 2025 15:12
Variadic Views
import SwiftUI
struct MyValue: _ViewTraitKey {
static var defaultValue: Int = 0
}
extension View {
func myValue(_ value: Int) -> some View {
_trait(MyValue.self, value)
}
@JSerZANP
JSerZANP / ContentView.swift
Created March 4, 2021 14:01
communication between native(swiftUI) and wkwebview
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
var webView: WKWebView?
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.webView = webView
}
@br3ndonland
br3ndonland / github-actions-notes.md
Last active February 20, 2026 21:07
Getting the Gist of GitHub Actions
@mjm
mjm / LinkedText.swift
Created May 21, 2020 03:56
Tappable links in SwiftUI Text view
import SwiftUI
private let linkDetector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
struct LinkColoredText: View {
enum Component {
case text(String)
case link(String, URL)
}
@artemnovichkov
artemnovichkov / UIApplication+UserInterfaceStyle.swift
Last active December 11, 2020 22:49
Updating application with new user interface style
import UIKit
public extension UIApplication {
func override(_ userInterfaceStyle: UIUserInterfaceStyle) {
if supportsMultipleScenes {
for connectedScene in connectedScenes {
if let scene = connectedScene as? UIWindowScene {
for window in scene.windows {
window.overrideUserInterfaceStyle = userInterfaceStyle
@shaps80
shaps80 / InfiniteIterator.swift
Created October 20, 2017 12:08
An iterator that automatically wraps back to the `firstIndex` after the `endIndex` is reached.
import Foundation
public struct InfiniteIterator<Base: Collection>: IteratorProtocol {
private let collection: Base
private var index: Base.Index
public init(collection: Base) {
self.collection = collection
self.index = collection.startIndex
@klundberg
klundberg / copyonwrite.swift
Last active April 1, 2017 23:27
Encapsulating copy-on-write behavior in a reusable way.
// Written using Swift 3.0.x
fileprivate final class Box<T> {
let unbox: T
init(_ value: T) {
unbox = value
}
}
public struct CopyOnWrite<T: AnyObject> {
@benbahrenburg
benbahrenburg / KeyChainAccessGroupHelper.swift
Last active July 5, 2021 21:18
KeyChainAccessGroupHelper - Making it easier to deal with Keychain Access Groups
//
// KeyStorage - Simplifying securely saving key information
//
// KeyChainAccessGroupHelper.swift
// Created by Ben Bahrenburg on 12/30/16.
// Copyright © 2017 bencoding.com. All rights reserved.
//
import Foundation
import Security
@cabotmoose
cabotmoose / KeychainManager.swift
Created May 6, 2016 21:41
Swift 2 Gude to Keychain Encryption: Part One
//
// KeychainManager.swift
// KeychainAccess
//
// Created by Cameron Smith on 5/6/16.
// Copyright © 2016 Flying Moose Development. All rights reserved.
//
import Foundation
@MihaelIsaev
MihaelIsaev / HMAC.swift
Last active December 4, 2019 04:51
Easy to use Swift implementation of CommonCrypto HMAC. You can easily hash your String to: md5, sha1, sha224, sha256, sha384, sha512 with pure Swift.
//
// HMAC.swift
//
// Created by Mihael Isaev on 21.04.15.
// Copyright (c) 2014 Mihael Isaev inc. All rights reserved.
//
// ***********************************************************
//
// How to import CommonCrypto in Swift project without Obj-c briging header
//