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 UsernameInputView: View { | |
@State var username = "" | |
var body: some View { | |
TextField(username, text: $username) | |
} | |
} |
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 UsernameView: View { | |
let username: String | |
var body: some View { | |
Text(username) | |
} | |
} |
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
view = f(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
// | |
// RouteBuilder.swift | |
// RouteBuilder | |
// | |
// Created by Dino on 09/07/2019. | |
// Copyright © 2019 Dino Srdoc. All rights reserved. | |
// | |
import Foundation |
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
// | |
// ContentView.swift | |
// SampleUI | |
// | |
// Created by Dino on 26/06/2019. | |
// | |
// Source for the Observer class: https://www.reddit.com/r/swift/comments/c5pr0z/i_created_a_cool_utility_for_when_youre_working/ | |
// Running this with the Xcode 11 Beta 2 causes the compiler to hang infinitely for me. | |
// Try it out! |
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 | |
func measure(label: String, printResults output: Bool = true, _ block: @escaping () -> Void) -> Double { | |
let numberOfTests = 5 | |
var avgExecutionTime : CFAbsoluteTime = 0 | |
for _ in 1...numberOfTests { | |
let start = CFAbsoluteTimeGetCurrent() | |
block() |
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
enum Validators { | |
static let email: (UITextField) -> Bool = { textField in | |
return textField.text?.trimmed.isValidEmailFormat() ?? false | |
} | |
static let phone: (UITextField) -> Bool = { textField in | |
return textField.text?.trimmed.isValidPhoneNumber() ?? false | |
} | |
static let nonEmpty: (UITextField) -> Bool = { textField in |
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
statusItemController.onClick = { statusItem in | |
DarkMode.toggle() | |
if DarkMode.isEnabled { | |
statusItem.button?.title = "on" | |
} else { | |
statusItem.button?.title = "off" | |
} | |
} |
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
@objc private func performClick(_ sender: Any) { | |
onClick?(statusItem) | |
} |
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
init(statusItem: NSStatusItem) { | |
self.statusItem = statusItem | |
self.statusItem.button?.target = self | |
self.statusItem.button?.action = #selector(performClick(_:)) | |
} |