Skip to content

Instantly share code, notes, and snippets.

View 7foots's full-sized avatar

7foots

View GitHub Profile
@7foots
7foots / ArrayRemoveFirstWhere.swift
Created April 13, 2022 07:28
Swift Array removeFirst(where:)
import Foundation
extension Array {
mutating func removeFirst(where shouldBeRemoved: (Element) throws -> Bool) rethrows {
guard let index = try firstIndex(where: shouldBeRemoved) else {
return;
}
remove(at: index)
}
extension Dictionary where Key == Int64, Value == SKNode {
func int64key(_ key: (Int32, Int32)) -> Int64 {
return (Int64(key.0) << 32) | Int64(key.1)
}
subscript(_ key: (Int32, Int32)) -> SKNode? {
get {
return self[int64key(key)]
}
set(newValue) {
@7foots
7foots / UISearchControllerCancelButton.swift
Last active March 18, 2020 09:07
Quick access to cancel button in UISearchController
/**
Example for customize your cancel button:
let controller = UISearchController(searchResultsController: nil)
controller.searchBar.showsCancelButton = true
if let button = controller.cancelButton() {
// Customize button
let iconImage = UIImage(named: "icon")
button.isEnabled = true