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 tableSizeKeyPath = \Table.size.width // KeyPath<Table, Int> | |
let tableMaterialKeyPath = \Table.material // KeyPath<Table, String> | |
let table = Table( | |
size: .init(width: 100, height: 20), | |
material: "wood" | |
) | |
print(table[keyPath: tableSizeKeyPath]) // 100 |
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
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 | |
} |
NewerOlder