Skip to content

Instantly share code, notes, and snippets.

//
// UIScrollView+RACSupport.h
// Taskworld
//
// Created by Kittinun Vantasin on 8/5/15.
// Copyright (c) 2015 Taskworld. All rights reserved.
//
@import UIKit;
@khanlou
khanlou / MD5StringTest.swift
Last active April 12, 2019 09:18
MD5 and SHA1 on String in Swift 3
import XCTest
@testable import <#project#>
class StringMD5Test: XCTestCase {
func testMD5() {
let string = "soroush khanlou"
XCTAssertEqual(string.md5, "954d741d14b14002d1ba88f600eee635")
@briankc
briankc / NSScreen+CGDirectDisplayID.swift
Last active August 7, 2023 16:38
Get display ID from NSScreen for use with CGDirectDisplay API
import Cocoa
import CoreGraphics
extension NSScreen {
var displayID: CGDirectDisplayID {
return deviceDescription["NSScreenNumber"] as? CGDirectDisplayID ?? 0
}
}
@gonzalezreal
gonzalezreal / KeyedDecodingContainer+EmptyRepresentable.swift
Last active January 11, 2023 08:25
A technique to avoid having optional array properties in your models when decoding JSON using Swift 4
/// A type that has an "empty" representation.
public protocol EmptyRepresentable {
static func empty() -> Self
}
extension Array: EmptyRepresentable {
public static func empty() -> Array<Element> {
return Array()
}
}
@kdeda
kdeda / View+NSWindow.swift
Last active March 10, 2024 13:31
Open/Close NSWindow from SwiftUI.View
import SwiftUI
/**
hack to avoid crashes on window close, and remove the window from the
NSApplication stack, ie: avoid leaking window objects
*/
fileprivate final class WindowDelegate: NSObject, NSWindowDelegate {
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApp.removeWindowsItem(sender)
return true