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
| struct Paragraph { | |
| var words: String | |
| } | |
| struct Chapter { | |
| var title: String | |
| var content: [Paragraph] | |
| } |
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 UIImage { | |
| enum HEICError: Error { | |
| case heicNotSupported | |
| case cgImageMissing | |
| case couldNotFinalize | |
| } | |
| static var isHEICSupported: Bool = { | |
| let data = NSMutableData() |
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
| private static let toSuper: [Character: String] = ["0": "\u{2070}", | |
| "1": "\u{00B9}", | |
| "2": "\u{00B2}", | |
| "3": "\u{00B3}", | |
| "4": "\u{2074}", | |
| "5": "\u{2075}", | |
| "6": "\u{2076}", | |
| "7": "\u{2077}", | |
| "8": "\u{2078}", | |
| "9": "\u{2079}", |
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
| struct Dice: Codable { | |
| var range: Range<Int> | |
| init<R: RangeExpression>(range expr: R) where R.Bound == Int { | |
| range = expr.relative(to: Range<Int>(Int.min...Int.max-1)) | |
| } | |
| func roll() -> Int { | |
| return Int.random(in: range) |
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
| enum Result<Success, Failure: Error> { | |
| case success(Success) | |
| case failure(Failure) | |
| func get() throws -> Success { | |
| switch self { | |
| case .success(let success): | |
| return success | |
| case .failure(let failure): | |
| throw failure |
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
| enum Coin { | |
| case heads | |
| case tails | |
| var isHeads: Bool { | |
| switch self { | |
| case .heads: | |
| return true | |
| case .tails: | |
| return 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
| func compute(_ a: inout Int, _ b: inout Int) { | |
| b = 100 | |
| a = 10 | |
| } | |
| var x = 0 | |
| var y = 0 | |
| compute(&x, &y) |
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 | |
| extension String.StringInterpolation { | |
| private static let toSuper: [Character: String] = ["0": "\u{2070}", | |
| "1": "\u{00B9}", | |
| "2": "\u{00B2}", | |
| "3": "\u{00B3}", | |
| "4": "\u{2074}", | |
| "5": "\u{2075}", |
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
| enum Direction { | |
| case north, east, south, west | |
| var left: Direction { | |
| switch self { | |
| case .north: return .west | |
| case .west: return .south | |
| case .south: return .east | |
| case .east: return .north | |
| } |
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
| enum Direction { | |
| case north, east, south, west | |
| var left: Direction { | |
| switch self { | |
| case .north: return .west | |
| case .west: return .south | |
| case .south: return .east | |
| case .east: return .north | |
| } |