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
/// Pure function mapping new state to a new `TableViewModel`. This is invoked each time the state updates | |
/// in order for ReactiveLists to update the UI. | |
static func viewModel(forState groups: [ToolGroup]) -> TableViewModel { | |
// Create a section for every tool group | |
let sections: [TableSectionViewModel] = groups.map { group in | |
// Create a single cell for every tool | |
let cellViewModels = group.tools.map { ToolTableCellModel(tool: $0) } | |
return TableSectionViewModel( | |
headerTitle: group.name, | |
headerHeight: 44, |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
struct IssueAssignee { | |
let issueUid: String | |
let assigneeUid: String | |
} | |
struct IssueFollower { |
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 XCTest | |
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages | |
/// we support. | |
final class L10NTests: XCTestCase { | |
func testLocalizations() { | |
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"] | |
for locale in locales { |
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
/// A wrapper around `NSUserDefaults` access for settings that are specific to the PlanGrid app. | |
/// `NSUserDefaults` should always be accessed through this type, this way we have a good overview | |
/// of all the settings the app supports and we can document them. | |
@objc final class PlanGridUserDefaults: NSObject { | |
/// Keeps track of whether or not a user has already used the annotation filter feature. | |
static var hasUsedAnnotationFilterFeature = UserDefaultsProperty<Bool>("HasUsedAnnotationFilterFeature") | |
} | |
/// A property that wraps around a value that is persisted to NSUserDefaults. |
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
// Want to check equality of two Date instances *in your tests?* (you should never rely on this in | |
// production). Add this extension to avoid | |
// rounding errors when using different initializers. | |
// See: https://twitter.com/benjaminencz/status/794606769360076800 | |
extension Date { | |
public static func ==(lhs: Date, rhs: Date) -> Bool { | |
return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate || | |
lhs.timeIntervalSince1970 == rhs.timeIntervalSince1970 | |
} | |
} |
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
extension Date { | |
public static func ==(lhs: Date, rhs: Date) -> Bool { | |
return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate || | |
lhs.timeIntervalSince1970 == rhs.timeIntervalSince1970 | |
} | |
} |
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
// Thanks to @jckarter for pointing that this is just Optional's map implementation... | |
{ $0.map(f) } | |
/// Takes a function with non-optional input and non-optional return and lifts it to a function | |
/// with optional input and optional return. | |
/// The lifted function will return `nil` iff the input is `nil`, otherwise the input will be | |
/// applied to the original function which will return a non-`nil` value. | |
public func liftToOptional<T,U>(_ f: @escaping (T) -> U) -> (T?) -> U? { | |
return { arg in | |
guard let arg = arg else { return 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
// Don't actually do this... | |
func lift<A, B, C>(input: (A, B, C)) -> (A!, B!, C!) { | |
return (Optional(input.0)!, Optional(input.1)!, Optional(input.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
//: Playground - noun: a place where people can play | |
import Cocoa | |
protocol Action {} | |
final class Store<State> { | |
typealias Reducer = (Action, State) -> (State, [Any]) | |
var state: State |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
struct Person { | |
let name: String | |
let age: Int | |
} | |
struct Car { |
NewerOlder