This file contains 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
/// | |
/// Allow you to register cells with code | |
/// <CellName>.reuseIdentifier | |
extension UICollectionReusableView { | |
static var reuseIdentifier: String { | |
return String(describing: Self.self) | |
} | |
} | |
/// |
This file contains 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 | |
final class MessagePrinter { | |
private let decoder = MessageDecoder() | |
func printEncodedMessage(_ encodedMessage: [Int]) { | |
decoder.decodeMessage(encodedMessage) { message in | |
self.printDecodedMessage(message) | |
} | |
} |
This file contains 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
struct Size { | |
let width: Int | |
let height: Int | |
} | |
struct Table { | |
let size: Size | |
let material: String | |
} |
This file contains 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 matrixFirstCellValue = \Matrix[0,0] | |
struct Matrix { | |
var data: [[Int]] | |
subscript(row: Int, column: Int) -> Int? { | |
return data[column][row] | |
} | |
} |
This file contains 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 array = [1,2,3,4,5] | |
let arrayFirstItemKeyPath = \[Int][0] | |
let firstArrayItem = array[keyPath: arrayFirstItemKeyPath] // -> 1 |
This file contains 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
struct TableStructMapper<T> { | |
let sizeWidthdKeyPath: KeyPath<T, Int> | |
let sizeHeightKeyPath: KeyPath<T, Int> | |
let materialKeyPath: KeyPath<T, String> | |
func map(with mapper: T) -> Table { | |
return .init( | |
size: .init( | |
width: mapper[keyPath: sizeWidthdKeyPath], | |
height: mapper[keyPath: sizeHeightKeyPath] |
This file contains 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
struct TableDTO: Codable { | |
let width: Int | |
let height: Int | |
let material: String | |
enum CodingKeys: String, CodingKey { | |
case width | |
case height | |
case material | |
} |
This file contains 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 Sequence { | |
func sorted<T: Comparable>(by keyPath: KeyPath<Element, T>) -> [Element] { | |
return sorted { | |
$0[keyPath: keyPath] < $1[keyPath: keyPath] | |
} | |
} | |
} | |
let sortedTables = tables.sorted(by: \.size.width) |
This file contains 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
struct Size { | |
var width: Int | |
let height: Int | |
} | |
enum Material: String { | |
case wood | |
case iron | |
} |
This file contains 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 Size { // Changed to class | |
var width: Int | |
let height: Int | |
init(width: Int, height: Int) { | |
self.width = width | |
self.height = height | |
} | |
} |
NewerOlder