✅ Works on macOS Sonoma, Ventura, Monterey (Intel & Apple Silicon)
✅ Free & Open Source
✅ No jailbreak required
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol MyDelegate: AnyObject { | |
| func didFire(string: String) | |
| } | |
| final class AsyncDelegate<Element> { | |
| let events: AsyncStream<Element> | |
| let continuation: AsyncStream<Element>.Continuation | |
| init(bufferPolicy: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded) { | |
| (self.events, self.continuation) = AsyncStream<Element>.makeStream( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UITableView { | |
| func updateTableHeaderView(with view: UIView?) { | |
| guard | |
| let view = view | |
| else { | |
| tableHeaderView = nil | |
| return | |
| } | |
| let containerView = UIView() | |
| containerView.translatesAutoresizingMaskIntoConstraints = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Collection where Element: Collection { | |
| func transposed() -> [[Element.Element]]? { | |
| guard let maxCount = self.map({$0.count}).max() else {return nil} | |
| var result = [[Element.Element?]](repeating: [Element.Element?](repeating: nil, count: self.count), count: maxCount) | |
| for (r,row) in self.enumerated() { | |
| for (c,v) in row.enumerated() { | |
| result[c][r] = v | |
| } | |
| } | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| protocol DelegateProtocol: class { | |
| } | |
| protocol Delegatable { | |
| associatedtype DelegateType: DelegateProtocol | |
| var delegate: DelegateType? { get set } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class LinkedList<T> { | |
| class Node<T> { | |
| var value: T | |
| var next: Node? | |
| init (value: T){ | |
| self.value = value | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| /// A list is either empty or it is composed of a first element (head) | |
| /// and a tail, which is a list itself. | |
| /// | |
| /// See http://www.enekoalonso.com/projects/99-swift-problems/#linked-lists | |
| class List<T> { | |
| var value: T | |
| var nextItem: List<T>? | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let xs = [3,5,1,4,6,3,9,11,1,0,3] | |
| let ys = ["t","e","a","z","o","v","p"] | |
| extension Array where Element: Comparable { | |
| func selectionSort() -> [Element] { | |
| guard self.count > 1 else {return self} | |
| var result = self | |
| for index in (0..<count - 1) { | |
| var indexLowest = index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array where Element == Int { | |
| var equilibriumIndexes: [Element]? { | |
| var idxs = [Element]() | |
| var sum = reduce(0,+) | |
| var leftSum = 0 | |
| let count = self.count | |
| for i in 0..<count { | |
| sum = sum - self[i] | |
| if leftSum == sum { | |
| idxs.append(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol StackProtocol { | |
| associatedtype ElementType | |
| var isEmpty: Bool { get } | |
| mutating func pop() -> ElementType? | |
| mutating func push(_ value: ElementType) | |
| } | |
NewerOlder