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 UIKit | |
fileprivate extension Int { | |
var rgbaPercentage: CGFloat { | |
return CGFloat(self) / 255.0 | |
} | |
} | |
enum UIColorInputError: Error { | |
case invalidInputColor |
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
// | |
// LoopingIterator.swift | |
// | |
// Created by Chris Nevin on 01/11/2016. | |
// Copyright © 2016 CJNevin. All rights reserved. | |
// | |
import Foundation | |
public struct LoopingIterator<Base: Collection> : IteratorProtocol { |
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
func fold(_ array: [Int], times: Int) -> [Int] { | |
let m = array.count / 2 | |
let middle = (array.count & 1 == 1 ? [array[m]] : []) | |
return times > 0 ? fold(zip(array.prefix(m), array.suffix(m).reversed()).map({ $0 + $1 }) + middle, times: times - 1) : array | |
} | |
fold([1,2,3,4,5], times: 2) |
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
//: Domain | |
struct User { | |
let firstName: String | |
let lastName: String | |
} | |
struct LoginUseCase { | |
enum Error: Swift.Error { | |
case invalidCredentials |
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
let replacements = [("3", "*"), ("7", "3"), ("*", "7")] | |
func twisted37(_ val: Int) -> Int { | |
return Int(replacements.reduce(String(val), { $0.replacingOccurrences(of: $1.0, with: $1.1) })) ?? 0 | |
} | |
func sortTwisted37(_ arr: [Int]) -> [Int] { | |
return arr.sorted(by: { twisted37($0) < twisted37($1) }) | |
} | |
assert(sortTwisted37([1,2,3,4,5,6,7,8,9]) == [1, 2, 7, 4, 5, 6, 3, 8, 9]) |
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 | |
import RxSwift | |
import Nimble | |
class Mock<T> { | |
private var object: T | |
private var count: Int = 0 | |
init(object: T) { | |
self.object = object |
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 | |
protocol JsonDeserializable { | |
init(json: Any) throws | |
} | |
struct JsonParser { | |
enum Error: Swift.Error { | |
case invalidKey(String) | |
case invalidJson |
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 RxSwift | |
struct List { | |
struct Item { | |
let name: String | |
} | |
let items: [Item] | |
} | |
protocol GetListRepository { |
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
protocol GetListRepository { | |
func get(uniqueId: String, startingAt offset: Int, limit: Int) -> Single<List> | |
} | |
struct GetListUseCase { | |
enum Result { | |
case success(List) | |
case failure(Error, Int) | |
} |
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
class Presenter<T> { | |
private var view: T? | |
func attachView(_ view: T) { | |
self.view = view | |
} | |
func detachView() { | |
self.view = nil | |
} |
OlderNewer