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 DeepCopyable { | |
| init(deeplyCopying: Self) | |
| } | |
| extension Array: DeepCopyable where Element: DeepCopyable { | |
| init(deeplyCopying: [Element]) { | |
| self = deeplyCopying.map(Element.init(deeplyCopying:)) | |
| } | |
| } |
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 Player { | |
| var name: String { get } | |
| var hitpoints: Int { get set } | |
| } | |
| protocol DeathWathable { | |
| func playerDied(_ player: Player) | |
| } | |
| @propertyDelegate |
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 LogMessage: StringInterpolationProtocol, CustomStringConvertible { | |
| var message: String | |
| var severity = 30 | |
| var superUserAction = false | |
| var user: User? | |
| var description: String { | |
| return message | |
| } |
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 Employee { | |
| var name: String | |
| var id: String | |
| var salary: Int | |
| var department: String | |
| } | |
| let employees = [ | |
| Employee(name: "Tyler Bennett", id: "E10297", salary: 32000, department: "D101"), | |
| Employee(name: "John Rappl", id: "E21437", salary: 47000, department: "D050"), |
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 { | |
| func slice(from: Int = 0, to: Int = Int.max, increment: Int = 1) -> [Element] { | |
| let endIdx: Index | |
| let startIdx: Index | |
| if to >= count { | |
| endIdx = endIndex | |
| } else if to < 0 { | |
| endIdx = index(endIndex, offsetBy: to, limitedBy: startIndex) ?? startIndex | |
| } else { |
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 | |
| infix operator <- | |
| infix operator <<- | |
| func <- <A1: Actor, MessageType>(actor: A1?, data: MessageType) where A1.MessageType == MessageType { | |
| actor?.receive(ActorMessage(sender: nil, data: data)) | |
| } | |
| func <<- <A1: Actor, A2, MessageType>( |
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 | |
| guard let path = Array(CommandLine.arguments.dropFirst()).first else { | |
| fatalError() | |
| } | |
| let fileData = FileManager.default.contents(atPath: path)! | |
| let eventData = String(data: fileData, encoding: .utf8)! | |
| for line in eventData.components(separatedBy: "\n") { |
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 v1 = 1.0 | |
| let v2 = 2.0 | |
| var v3 = 4.0 | |
| var v4 = 0.0 | |
| var v5 = 0.0 | |
| var v6 = 0.0 | |
| var v7 = 0.0 | |
| var v8 = 0.0 | |
| var v10 = 0.0 |
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 DiscontinuousRangeIterator<Bound: Strideable>: IteratorProtocol where Bound.Stride: SignedInteger { | |
| let ranges: [ClosedRange<Bound>] | |
| var curRange = 0 | |
| var curIterator: ClosedRange<Bound>.Iterator? | |
| init(range: DiscontinuousRange<Bound>) { | |
| self.ranges = range.ranges | |
| if !ranges.isEmpty { | |
| curIterator = ranges[0].makeIterator() |
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 | |
| typealias TwoIntsOneInt = @convention(c) (Int, Int) -> Int | |
| let code = [ | |
| 0x55, // push rbp | |
| 0x48, 0x89, 0xE5, // mov rbp, rsp | |
| 0x48, 0x8D, 0x04, 0x37, // lea rax, [rdi + rsi] | |
| 0x5D, // pop rbp | |
| 0xC3 // ret |