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 | |
public extension Array { | |
// Iterate through all elements in pair tuples | |
// e.g. [1, 2, 3, 4].allPairs = [(1, 2), (2, 3), (3, 4)] | |
var allPairs: [(Element, Element)] { | |
var array: [(Element, Element)] = [] | |
for i in 0..<self.count - 1 { | |
array.append((self[i], self[i+1])) | |
} |
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 UIKit | |
public extension UIColor { | |
convenience init(hex: String) { | |
let r, g, b, a: CGFloat | |
var hex = hex | |
if hex.hasPrefix("#") { hex = String(hex.dropFirst()) } | |
if hex.count == 6 { |
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 | |
import XcodeKit | |
class SourceEditorCommand: NSObject, XCSourceEditorCommand { | |
// Reverses code on selected lines | |
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void { | |
let lines = invocation.buffer.lines as? [String] ?? [] |
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 data = """ | |
{ | |
"response": [ | |
{ | |
"name": "Kitty", | |
}, | |
{ | |
"name": "Doggy", | |
} | |
] |
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 exampleData = """ | |
[ | |
{ | |
"type": "cat", | |
"name": "Kitty", | |
}, | |
{ | |
"type": "dog", | |
"name": "Doggy", | |
} |
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 LossyArray<Element: Decodable>: Decodable { | |
private(set) var elements: [Element] | |
init(from decoder: Decoder) throws { | |
var container = try decoder.unkeyedContainer() | |
var elements = [Element]() | |
if let count = container.count { | |
elements.reserveCapacity(count) | |
} |
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 AnimalContainer: Decodable { | |
let animal: Animal | |
enum AnimalType: String, Decodable { | |
case cat | |
case dog | |
} | |
enum CodingKeys: String, CodingKey { | |
case type |
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 UserSettings: Codable { | |
let someBool: Bool | |
let someDate: Date | |
enum CodingKeys: String, CodingKey { | |
case someBool = "someDifferentKeyBool" | |
case someDate = "someDifferentKeyDate" | |
} | |
} |
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
e |