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
| #!/usr/bin/env ruby | |
| # This script walks thru all the files in a Xcode project's groups belong to the target they are supposed to | |
| # according to group names found while walking the groups hierarchy. | |
| # | |
| # This example only focuses on test files and groups/targets ending with "...Tests" | |
| require 'xcodeproj' | |
| def check(group, all_targets, walk_path, ctx_target_name = nil, ctx_expected_files_list = nil) |
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
| /*: | |
| This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI | |
| The only purpose of this code is to implement those wrappers myself | |
| just to understand how they work internally and why they are needed, | |
| ⚠️ This is not supposed to be a reference implementation nor cover all | |
| subtleties of the real Binding and State types. | |
| The only purpose of this playground is to show how re-implementing | |
| them myself has helped me understand the whole thing better |
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 Demo { | |
| case simple | |
| case oneValue(Int) | |
| case twoValues(String, Double) | |
| case threeValues(one: Int, two: Float, [Int]) | |
| } | |
| //: # Direct exposition in the enum | |
| //: ## Sourcery Template |
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
| // Xcode 11b1 | |
| @propertyDelegate | |
| struct Clamped<Value: Comparable> { | |
| private var storage: Value | |
| private var clamp: (Value) -> Value | |
| init(min: Value, max: Value, initialValue: Value) { | |
| let clampingFunction = { ($0...$0).clamped(to: min...max).lowerBound } | |
| self.storage = clampingFunction(initialValue) |
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
| // Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange | |
| import Foundation | |
| struct RegEx { | |
| let regex: NSRegularExpression | |
| init(pattern: String, options: NSRegularExpression.Options = []) throws { | |
| self.regex = try NSRegularExpression(pattern: pattern, options: options) | |
| } |
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 | |
| protocol TransformerType { | |
| associatedtype BaseType | |
| associatedtype TypeForCoding: Codable | |
| static var encodeTransform: (BaseType) throws -> TypeForCoding { get } | |
| static var decodeTransform: (TypeForCoding) throws -> BaseType { get } | |
| } | |
| @propertyWrapper |
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 CustomMatcher<Value> { | |
| let closure: (Value) -> Bool | |
| static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool { | |
| caseValue.closure(switchValue) | |
| } | |
| static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool { | |
| switchValue.closure(caseValue) | |
| } | |
| } |
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 Contact: Decodable, CustomStringConvertible { | |
| var id: String | |
| @NestedKey | |
| var firstname: String | |
| @NestedKey | |
| var lastname: String | |
| @NestedKey | |
| var address: String | |
| enum CodingKeys: String, NestableCodingKey { |
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
| //: ## Demo | |
| struct User: CustomStringConvertible { | |
| let name: String | |
| let age: Int | |
| var description: String { "\(name) (\(age))" } | |
| } | |
| let users = [ | |
| User(name: "Bob", age: 22), |
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
| // Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange | |
| import Foundation | |
| struct RegEx<Names> { | |
| let regex: NSRegularExpression | |
| init(pattern: String, options: NSRegularExpression.Options = []) throws { | |
| self.regex = try NSRegularExpression(pattern: pattern, options: options) | |
| } |