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
| guard fileExists() == true else { | |
| return | |
| } | |
| let descriptor = open(self.filePath, O_EVTONLY) | |
| if descriptor == -1 { | |
| return | |
| } | |
| self.eventSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: self.fileSystemEvent, queue: self.dispatchQueue) |
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 MyOtherProtocol { | |
| associatedtype ItemType | |
| mutating func append(_ item: ItemType) | |
| var count: Int { get } | |
| subscript(i: Int) -> ItemType { get } | |
| } | |
| class Testing: MyOtherProtocol { | |
| typealias ItemType = Int |
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 Node where T: Equatable { | |
| func printItemTitle(item: T, secondItem: T) -> String { | |
| if item == secondItem { | |
| return "equal" | |
| } else { | |
| return item.itemTitle | |
| } | |
| } | |
| } |
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 MyCustomProtocol { | |
| var itemTitle: String { get } | |
| } | |
| class Node<T: MyCustomProtocol> { | |
| var item: T | |
| var next: Node? | |
| init(withItem item: T) { | |
| self.item = item |
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
| class DASelectionSort<T: Comparable> { | |
| public static func sort(_ items: [T]) -> [T] { | |
| var result = items | |
| let length = result.count | |
| for i in 0..<length { | |
| var minIndex = i | |
| for j in i+1..<length { |
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 Node { | |
| func processItem(item: T) { | |
| // Access type parameter in the extension | |
| } | |
| } |
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
| class Node<T> { | |
| var item: T | |
| var next: Node? | |
| init(withItem item: T) { | |
| self.item = item | |
| } | |
| } |
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
| func genericFunction<Item>(item: Item, secondItem: Item) { | |
| // do something useful with these two items :) | |
| } | |
| // Integers as parameters | |
| genericFunction(item: 2, secondItem: 3) | |
| // Strings as parameters | |
| genericFunction(item: "first", secondItem: "second") |
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
| class DAQuickSort<T: Comparable> { | |
| public static func sort(_ items: [T]) -> [T] { | |
| var result = items | |
| result.shuffle() | |
| sort(original: &result, low: 0, high: result.count - 1) | |
| 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
| class DAMergeSort<T: Comparable> { | |
| public static func sort(_ items: [T]) -> [T] { | |
| var result = items | |
| var temp = result | |
| sort(original: &result, temp: &temp, low: 0, high: result.count - 1) | |
| return result | |
| } |
NewerOlder