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
func logIn() { | |
// Your code to log in | |
} | |
enum Tab { | |
case profile | |
case settings | |
} | |
func selectTabBar(tab: Tab) { |
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
step("I log in") { | |
// Your code to log in | |
} | |
step("I select the (profile|settings) tab") { (tabType: String) in | |
switch tabType { | |
case "profile": // Your code to select the profile tab | |
case "settings": // Your code to select the settings tab | |
default: XCTFail() | |
} |
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
func test_navigatingToSettings() { | |
Given("I log in") | |
When("I select the settings tab") | |
Then("I see the settings screen") | |
} |
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
Given(I: logIn) | |
When(I: { | |
selectTabBar(tab: .settings) | |
}) | |
Then(I: seeSettingsScreen) |
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 Step { | |
@discardableResult | |
init(I handler: () -> Void) { | |
handler() | |
} | |
@discardableResult | |
init(I handler: @autoclosure () -> Void) { | |
handler() |
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
func test_navigatingToSettings() { | |
Given(I: logIn) | |
When(I: selectTabBar(tab: .settings)) | |
Then(I: seeSettingsScreen) | |
} |
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
class Cell: UITableViewCell { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
let settings = Settings() // This is me being sneaky, you really need to get this from a Realm | |
accessoryView = SettingsSwitch(object: settings, keyPath: \Settings.prefersFahrenheit) | |
} | |
} |
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 settingsSwitch = SettingsSwitch(object: settings, keyPath: \Settings.prefersFahrenheit) |
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
class SettingsSwitch<T>: UISwitch { | |
typealias BoolWritableKeyPath = WritableKeyPath<T, Bool> | |
private var object: T // This is the object we'll update when the value changes | |
private let keyPath: BoolWritableKeyPath // This is the key path we'll use to update the object | |
init(object: T, keyPath: BoolWritableKeyPath) { | |
self.object = object | |
self.keyPath = keyPath |
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 RealmSwift | |
class Settings: Object { | |
@objc private dynamic var _prefersFahrenheit: Bool = false // Realm requires all properties have a default value | |
var prefersFahrenheit: Bool { // I find it's best to define explicit getters and setters since you can transform primitives into enums etc. | |
get { | |
return _prefersFahrenheit | |
} |