diff --git a/100DaysOfSwift/Day5/Accepting parameters.swift b/100DaysOfSwift/Day5/Accepting parameters.swift new file mode 100644 index 0000000..57b8662 --- /dev/null +++ b/100DaysOfSwift/Day5/Accepting parameters.swift @@ -0,0 +1,10 @@ +// Accepting parameters +// https://www.hackingwithswift.com/sixty/5/2/accepting-parameters + +print("Hello, world!") + +func square(number: Int) { + print(number * number) +} + +square(number: 8) \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Default parameters.swift b/100DaysOfSwift/Day5/Default parameters.swift new file mode 100644 index 0000000..27e6131 --- /dev/null +++ b/100DaysOfSwift/Day5/Default parameters.swift @@ -0,0 +1,13 @@ +// Default parameters +// https://www.hackingwithswift.com/sixty/5/6/default-parameters + +func greet(_ person: String, nicely: Bool = true) { + if nicely == true { + print("Hello, \(person)!") + } else { + print("Oh no, it's \(person) again...") + } +} + +greet("Taylor") +greet("Taylor", nicely: false) \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Omitting parameter labels.swift b/100DaysOfSwift/Day5/Omitting parameter labels.swift new file mode 100644 index 0000000..b83a870 --- /dev/null +++ b/100DaysOfSwift/Day5/Omitting parameter labels.swift @@ -0,0 +1,8 @@ +// Omitting parameter labels +// https://www.hackingwithswift.com/sixty/5/5/omitting-parameter-labels + +func greet(_ person: String) { + print("Hello, \(person)!") +} + +greet("Taylor") \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Parameter labels.swift b/100DaysOfSwift/Day5/Parameter labels.swift new file mode 100644 index 0000000..a988404 --- /dev/null +++ b/100DaysOfSwift/Day5/Parameter labels.swift @@ -0,0 +1,14 @@ +// Parameter labels +// https://www.hackingwithswift.com/sixty/5/4/parameter-labels + +func square(number: Int) -> Int { + return number * number +} +let result = square(number: 8) + +// ------------------------------------------------------------- + +func sayHello(to name: String) { + print("Hello, \(name)!") +} +sayHello(to: "Taylor") \ No newline at end of file diff --git a/100DaysOfSwift/Day5/README.md b/100DaysOfSwift/Day5/README.md new file mode 100644 index 0000000..7aac759 --- /dev/null +++ b/100DaysOfSwift/Day5/README.md @@ -0,0 +1,16 @@ +# Day #5 + +--- + +**What I learned about** + +- **[Writing functions](/100DaysOfSwift/Day5/Writing%20functions.swift)** +- **[Accepting parameters](/100DaysOfSwift/Day5/Accepting%20parameters.swift)** +- **[Returning values](/100DaysOfSwift/Day5/Returning%20values.swift)** +- **[Parameter labels](/100DaysOfSwift/Day5/Parameter%20labelss.swift)** +- **[Omitting parameter labels](/100DaysOfSwift/Day5/Omitting%20parameter%20labels.swift)** +- **[Default parameters](/100DaysOfSwift/Day5/Default%20parameters.swift)** +- **[Variadic functions](/100DaysOfSwift/Day5/Variadic%20functions.swift)** +- **[Writing throwing functions](/100DaysOfSwift/Day5/Writing%20throwing%20functions.swift)** +- **[Running throwing functions](/100DaysOfSwift/Day5/Running%20throwing%20functions.swift)** +- **[inout parameters](/100DaysOfSwift/Day5/inout%20parameters.swift)** \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Returning values.swift b/100DaysOfSwift/Day5/Returning values.swift new file mode 100644 index 0000000..cc428a0 --- /dev/null +++ b/100DaysOfSwift/Day5/Returning values.swift @@ -0,0 +1,9 @@ +// Returning values +// https://www.hackingwithswift.com/sixty/5/3/returning-values + +func square(number: Int) -> Int { + return number * number +} + +let result = square(number: 8) +print(result) \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Running throwing functions.swift b/100DaysOfSwift/Day5/Running throwing functions.swift new file mode 100644 index 0000000..a9d576c --- /dev/null +++ b/100DaysOfSwift/Day5/Running throwing functions.swift @@ -0,0 +1,11 @@ +// Running throwing functions +// https://www.hackingwithswift.com/sixty/5/9/running-throwing-functions + +do { + try checkPassword("password") + print("That password is good!") +} catch { + print("You can't use that password.") +} + +// do starts a section of code that might cause problems, try is used before every function that might throw an error, and catch lets you handle errors gracefully. \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Variadic functions.swift b/100DaysOfSwift/Day5/Variadic functions.swift new file mode 100644 index 0000000..25b53c1 --- /dev/null +++ b/100DaysOfSwift/Day5/Variadic functions.swift @@ -0,0 +1,11 @@ +// Variadic functions +// https://www.hackingwithswift.com/sixty/5/7/variadic-functions + +print("Haters", "gonna", "hate") + +func square(numbers: Int...) { + for number in numbers { + print("\(number) squared is \(number * number)") + } +} +square(numbers: 1, 2, 3, 4, 5) \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Writing functions.swift b/100DaysOfSwift/Day5/Writing functions.swift new file mode 100644 index 0000000..e5527f7 --- /dev/null +++ b/100DaysOfSwift/Day5/Writing functions.swift @@ -0,0 +1,15 @@ +// Writing function +// https://www.hackingwithswift.com/sixty/5/1/writing-functions + +func printHelp() { + let message = """ +Welcome to MyApp! + +Run this app inside a directory of images and +MyApp will resize them all into thumbnails +""" + + print(message) +} + +printHelp() \ No newline at end of file diff --git a/100DaysOfSwift/Day5/Writing throwing functions.swift b/100DaysOfSwift/Day5/Writing throwing functions.swift new file mode 100644 index 0000000..567be22 --- /dev/null +++ b/100DaysOfSwift/Day5/Writing throwing functions.swift @@ -0,0 +1,14 @@ +// Writing throwing functions +// https://www.hackingwithswift.com/sixty/5/8/writing-throwing-functions + +enum PasswordError: Error { + case obvious +} + +func checkPassword(_ password: String) throws -> Bool { + if password == "password" { + throw PasswordError.obvious + } + + return true +} \ No newline at end of file diff --git a/100DaysOfSwift/Day5/inout parameters.swift b/100DaysOfSwift/Day5/inout parameters.swift new file mode 100644 index 0000000..0af17a2 --- /dev/null +++ b/100DaysOfSwift/Day5/inout parameters.swift @@ -0,0 +1,2 @@ +// inout parameters +// https://www.hackingwithswift.com/sixty/5/10/inout-parameters \ No newline at end of file diff --git a/100DaysOfSwift/README.md b/100DaysOfSwift/README.md index 57444e4..4a9c8df 100644 --- a/100DaysOfSwift/README.md +++ b/100DaysOfSwift/README.md @@ -13,4 +13,5 @@ - **[Day #1](/100DaysOfSwift/Day1/)** - variables, simple data types, and string interpolation - **[Day #2](/100DaysOfSwift/Day2/)** - arrays, dictionaries, sets, and enums - **[Day #3](/100DaysOfSwift/Day3/)** - operators and conditions -- **[Day #4](/100DaysOfSwift/Day4/)** - loops, loops, and more loops \ No newline at end of file +- **[Day #4](/100DaysOfSwift/Day4/)** - loops, loops, and more loops +- **[Day #5](/100DaysOfSwift/Day5/)** - functions, parameters, and errors \ No newline at end of file diff --git a/100DaysOfSwiftUI/README.md b/100DaysOfSwiftUI/README.md index 0f33aed..5eb9448 100644 --- a/100DaysOfSwiftUI/README.md +++ b/100DaysOfSwiftUI/README.md @@ -1,7 +1,17 @@ -# [100 Days of SwiftUI](https://www.hackingwithswift.com/100/swiftui) +# [100 Days of Swift](https://www.hackingwithswift.com/100/swiftui) --- **This folder is for the [100 Days of SwiftUI](https://www.hackingwithswift.com/100/swiftui) challenge.** **NOTE:** This is **[100 Days of SwiftUI](https://www.hackingwithswift.com/100/swiftui)**, not **[100 Days of Swift](https://www.hackingwithswift.com/100)** which is located [here](/100DaysOfSwift/) + +--- + +**Days 1-12: Introduction to Swift** + +- **[Day #1](/100DaysOfSwift/Day1/)** - variables, simple data types, and string interpolation +- **[Day #2](/100DaysOfSwift/Day2/)** - arrays, dictionaries, sets, and enums +- **[Day #3](/100DaysOfSwift/Day3/)** - operators and conditions +- **[Day #4](/100DaysOfSwift/Day4/)** - loops, loops, and more loops +- **[Day #5](/100DaysOfSwift/Day5/)** - functions, parameters, and errors \ No newline at end of file