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 datetime | |
from datetime import timedelta | |
first_time = datetime.datetime.now() | |
later_time = datetime.datetime.now() + timedelta(minutes=10) | |
difference = later_time - first_time |
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
# Exceptions | |
def ask_user_for_input(): | |
print("asking user for input") | |
number = int(input("Enter number: ")) | |
try: # capturing runtime errors | |
#ask_user_for_input() | |
#result = 1/0 | |
result = 4/2 |
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
# Ask the user for input for name | |
# Ask the user for priority | |
# create a task using name and priority | |
# add the task to list of tasks | |
# list to hold al the tasks | |
all_tasks = [] | |
class Task: |
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
# Creating a Class | |
class Car: | |
def __init__(self, make, model): # initializer/constructor | |
# define properties of the car | |
self.make = make | |
self.model = model | |
self.color = "White" |
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
//ContentView: | |
NavigationLink(destination: LoginView().accessibility(identifier: "loginView"), isActive: self.$registrationVM.showLoginView) { | |
EmptyView() | |
} | |
// Test | |
func test_should_register_successfully() { |
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 RegistrationViewModel: ObservableObject { | |
@Validated(.required(errorMessage: "First name cannot be empty")) | |
var firstname: String? = "" | |
@Validated(.required(errorMessage: "Last name cannot be empty")) | |
var lastname: String? = "" | |
@Validated(.required(errorMessage: "Username cannot be empty")) | |
var username: String? = "" |
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
static func required(errorMessage: String = "Is Empty") -> Validation { | |
return .init { value in | |
value.isEmpty ? .failure(.init(message: errorMessage)) : .success(()) | |
} | |
} |
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 RegistrationViewModel: ObservableObject { | |
@Validated(.required) | |
var firstname: String? = "" | |
@Validated(.required) | |
var lastname: String? = "" | |
@Validated(.required) |
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 Foundation | |
import ValidatedPropertyKit | |
extension Validation where Value == String { | |
static var required: Validation { | |
return .init { value in | |
value.isEmpty ? .failure("\(value) cannot be empty") : .success(()) | |
} | |
} |
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 ContentView: View { | |
@ObservedObject private var registrationVM = RegistrationViewModel() | |
var body: some View { | |
NavigationView { | |
Form { | |
VStack(spacing: 10) { | |
TextField("First name", text: $registrationVM.firstname.bound) |