Skip to content

Instantly share code, notes, and snippets.

@macabeus
macabeus / listClasses.swift
Last active November 13, 2023 23:21
List all classes that subscribe a protocol
// Many thanks to Code Different: http://stackoverflow.com/a/42749141/3440266
import Foundation
struct ClassInfo : CustomStringConvertible, Equatable {
let classObject: AnyClass
let classNameFull: String
let className: String
init?(_ classObject: AnyClass?) {
guard classObject != nil else { return nil }
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }
@gunhansancar
gunhansancar / VisualEffectViewExtensions.swift
Created February 16, 2017 13:49
In this gist you can find out how to fade in/fade out UIBlurEffect on UIVisualEffectView on iOS 10 and also earlier versions. Also added example ViewController to see how to use them in action. The below snippets are written in Swift3.
extension UIVisualEffectView {
func fadeInEffect(_ style:UIBlurEffectStyle = .light, withDuration duration: TimeInterval = 1.0) {
if #available(iOS 10.0, *) {
let animator = UIViewPropertyAnimator(duration: duration, curve: .easeIn) {
self.effect = UIBlurEffect(style: style)
}
animator.startAnimation()
}else {
@ole
ole / fun-with-string-interpolation.swift
Last active June 13, 2018 15:02
Fun with String Interpolation — For more information read my article at https://oleb.net/blog/2017/01/fun-with-string-interpolation/. — Dependencies: Foundation
/// An unescaped string from a potentially unsafe
/// source (such as user input)
struct UnsafeString {
var value: String
}
/// A string that either comes from a safe source
/// (e.g. a string literal in the source code)
/// or has been escaped.
struct SanitizedHTML {
@Maxdw
Maxdw / localize.swift
Last active April 5, 2023 17:29
genstrings for custom translation function
extension String {
func localizedWith(comment:String) -> String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: comment)
}
}
@velyan
velyan / StateMachine.swift
Last active March 4, 2020 18:31
Swift State Pattern
import Foundation
fileprivate protocol Statelike {
var stateMachine: StateMachine { get }
func logIn()
func logOut()
}
extension Statelike {
func logIn() {}
@AmitaiB
AmitaiB / SwiftXOR.swift
Created November 17, 2016 04:41
Swift 3 Logical XOR Operator
precedencegroup BooleanPrecedence { associativity: left }
infix operator ^^ : BooleanPrecedence
/**
Swift Logical XOR operator
```
true ^^ true // false
true ^^ false // true
false ^^ true // true
false ^^ false // false
```
@kutschenator
kutschenator / StaticallyAccessible.swift
Last active September 4, 2017 13:36
StaticallyAccessible
postfix operator ~
protocol StaticallyAccessible { }
extension StaticallyAccessible {
static postfix func ~ (c: Self) -> Self.Type {
return type(of: c)
}
var 🌩: Self.Type {
return type(of: self)
}
@jagrosh
jagrosh / Github Webhook Tutorial.md
Last active April 17, 2025 11:00
Simple Github -> Discord webhook

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings