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
//: ## 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 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) | |
} |
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 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 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 | |
let json = """ | |
{ | |
"data": { | |
"items": [ | |
{ "name": "Alice" }, | |
{ "name": "Bob" }, | |
{ "name": "Claudia" } | |
] |
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
//#! Swift 5 | |
import Foundation | |
import AppKit | |
//////////////////////////////////////////////////////////////////// | |
//: ## Type Definition | |
struct AttrString { | |
let attributedString: NSAttributedString |
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
#!/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 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
####################################### | |
# Check that some Build Settings (those defined by VERSION_SETTINGS below) are set on the right level (target/project) | |
####################################### | |
VERSION_SETTINGS = %w(GLOBAL_APP_VERSION GLOBAL_APP_BUILD_VERSION) | |
require 'xcodeproj' | |
project = Xcodeproj::Project.open('YOUR_PROJECT_NAME.xcodeproj') | |
target = project.targets.find("YOUR_TARGET_NAME").first | |
target.build_configurations.each do |bc| | |
## Don't allow some build settings at target level (but only at project level) |
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
#!/usr/bin/env ruby | |
require 'tmpdir' | |
require 'open3' | |
# The first parameter is supposed to be the path to the markdown file | |
input_file = ARGV.first | |
config_file = ARGV[1] || '.swiftlint.yml' | |
config_param = File.exist?(config_file) ? " --config #{File.realpath(config_file)}" : '' |
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 | |
//: ## Option 1: A Failable type for each item | |
//: In practice, it's very similar to the concept of the "Result" type that you see in most code bases (and that will be integrated in Swift 5), so if you already have a Result type, you might just want to use it instead, but if not, this is a super-simplification of it | |
enum Failable<T>: CustomStringConvertible { | |
case success(T) | |
case failure(Error) | |
var description: 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
#!/bin/bash | |
##### | |
# | |
# git-gerrit v1.1 | |
# O. Halligon, 2017.08.18 | |
# | |
##### | |
# | |
# Usage: | |
# |