-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix naming * Update basic and lasagna * Adjustements * Reorder exercises * Update basic and lasagna * Adjustements * Updates and fixes * Fixes * Fix tests case * Add new line * Fixed formatting * Run grammarly * Update the function definetion instructions * Update the example styling * Formatting fixes * Various improvements * Format the package file * format file * Remove file
- Loading branch information
1 parent
9c3f1dd
commit b8adc41
Showing
33 changed files
with
490 additions
and
399 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"blurb": "Swift is a statically-typed language, which means that every value has a known, fixed type at compile time.", | ||
"blurb": "Swift is a compiled, multi-paradigm language, that uses static typing.", | ||
"authors": [ | ||
"wneumann" | ||
"wneumann", | ||
"meatball133" | ||
], | ||
"contributors": [] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,146 @@ | ||
# About | ||
|
||
Swift is a statically-typed language, which means that every value has a known, fixed type at compile time. | ||
Swift is a compiled, multi-paradigm language. | ||
With the following goals: | ||
|
||
Swift has values of a number of fundamental data types that are similar to what is seen in other programming languages, including integers, booleans, and floating point numbers. In addition to these types, Swift also offers a number of more complex types that values can be, including arrays, dictionaries, and functions. | ||
- Have safety features to prevent errors in production | ||
|
||
Swift supports two types of [comments][comments]. Single line comments are preceded by `//` and multiline comments are inserted between `/*` and `*/`. | ||
- Having comparable speed to C-based languages | ||
|
||
[comments]: https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID315 | ||
- Having syntax that is a joy to read and write | ||
|
||
Swift was developed as a replacement for Objective-C, which was the primary language used for developing iOS and macOS applications. | ||
Swift was developed by Apple Inc. | ||
The language got its first release in 2014. | ||
It is now open source and is available on all Apple devices, Linux, and Windows. | ||
|
||
## Getting Started | ||
|
||
### Variables | ||
|
||
Values can be associated with names by defining a [variable][constants-variables] and assigning a value to that variable. | ||
That name may then be used to refer to that value throughout the program. | ||
Variables are _mutable_, which means that the value can be changed at any time. | ||
|
||
Variables are defined using the `var` keyword. | ||
|
||
```swift | ||
var variableName = 10 | ||
``` | ||
|
||
Swift is a type-safe, statically typed language, which means all values have a type at compile time. | ||
You can either explicitly specify the type of a variable or let the compiler [infer the type][type-infering] based on the assigned value. | ||
|
||
When assigning a value to a variable are there two ways either through explicit typing through [type annotations][type annotations] or implicit typing. | ||
|
||
```swift | ||
var explicitVar: Int = 10 // Explicitly typed | ||
var implicitVar = 10 // Implicitly typed | ||
``` | ||
|
||
Updating a variable's value is done using the `=` operator. | ||
|
||
````exercism/note | ||
The type of a variable, is fixed once it is initially defined. | ||
```swift | ||
variableName = 13 // update to new value | ||
// compiler error when assigning a different type | ||
variableName = "Hello, world!" // Cannot assign value of type 'String' to type 'Int' | ||
``` | ||
```` | ||
|
||
Variables may be declared without assigning a value by specifying the name and type, but they may not be used before a value is assigned. | ||
|
||
```swift | ||
var someInt: Int | ||
|
||
// This would trigger a compiler error | ||
// print(someInt) // Variable 'someInt' used before being initialized | ||
|
||
// Assign a value to the names | ||
someInt = 169 | ||
|
||
print(someInt) // Prints '169' | ||
``` | ||
|
||
### Constants | ||
|
||
[Constants][constants-variables] are similar to variables in that they are associated with a name and a value, but the value of a constant cannot be changed once it is initially assigned and is thereby _immutable_. | ||
Constants are defined using the `let` keyword. | ||
|
||
```swift | ||
let constantName = 10 // constant | ||
let explicitConstant: Int = 10 // Explicitly typed constant | ||
``` | ||
|
||
### Addition & Subtraction & Multiplication | ||
|
||
Swift has [operators][operators] for addition, subtraction, and multiplication. | ||
The operators are `+`, `-`, and `*` respectively. | ||
|
||
```swift | ||
print(1 + 1) // Prints 2 | ||
print(2 - 1) // Prints 1 | ||
print(2 * 2) // Prints 4 | ||
``` | ||
|
||
### Functions | ||
|
||
In Swift, [functions][functions] are a chunk of code that performs a task. | ||
A function has a return type and can thereby be used as a value and be parsed as arguments to other functions. | ||
In Swift are functions defined using the `func` keyword followed by the name of the function, arguments separated by commas, and a return type. | ||
|
||
The arguments are defined by an argument label, a parameter name followed by a semi-colon and then a type. | ||
The return type is defined by a `->` followed by the type of the return value. | ||
|
||
```swift | ||
func functionName(argumentName parameterName: ArgumentType) -> ReturnType { | ||
// function body | ||
} | ||
``` | ||
|
||
Swift arguments are a bit special compared to other languages, they use [argument labels][argument labels]. | ||
The argument label is used when calling the function. | ||
The parameter name is used inside the function body to refer to the argument value. | ||
If you only assign one name to the argument it will be used as both the argument label and the parameter name. | ||
When assigning the argument label name as: `_` so will the argument not have a label when calling the function, e.g: `functionName(argumentValue)` | ||
|
||
To call a function you use the function name followed by the argument label and the argument value, like this: | ||
|
||
```swift | ||
func functionName(argumentLabel parameterName: ArgumentType) -> ReturnType { | ||
// function body | ||
} | ||
|
||
// calling the function | ||
functionName(argumentLabel: argumentValue) | ||
``` | ||
|
||
All arguments are immutable by default and can't be changed inside the function. | ||
When a function has a return type most be sure to return a value of that type. | ||
That is done by using the `return` keyword followed by the value to return. | ||
|
||
```swift | ||
func addTen(number value: Int) -> Int { | ||
return value + 10 | ||
} | ||
|
||
// calling the function | ||
addTen(number: 10) // Returns 20 | ||
``` | ||
|
||
When functions don't return a value they have a return type of `Void`, which is the same as `()`, but the return type can also be omitted in these cases. | ||
|
||
### Comments | ||
|
||
Swift supports two types of [comments][comments]. | ||
Single line comments are preceded by `//` and multiline comments are inserted between `/*` and `*/`. | ||
|
||
[comments]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Comments | ||
[constants-variables]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Constants-and-Variables | ||
[type annotations]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Type-Annotations | ||
[type-infering]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Type-Safety-and-Type-Inference | ||
[functions]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Defining-and-Calling-Functions | ||
[arithmetical-operators]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/basicoperators/#Arithmetic-Operators |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,132 @@ | ||
# Introduction | ||
# About | ||
|
||
Swift is a statically-typed language, which means that every value has a known, fixed type at compile time. | ||
## Getting Started | ||
|
||
Swift has values of a number of fundamental data types that are similar to what is seen in other programming languages, including integers, booleans, and floating point numbers. In addition to these types, Swift also offers a number of more complex types that values can be, including arrays, dictionaries, and functions. | ||
### Variables | ||
|
||
Swift supports two types of comments. Single line comments start with `//` and continue to the following newline. Multiline comments are inserted between `/*` and `*/`. | ||
Values can be associated with names by defining a [variable][constants-variables] and assigning a value to that variable. | ||
That name may then be used to refer to that value throughout the program. | ||
Variables are _mutable_, which means that the value can be changed at any time. | ||
|
||
Variables are defined using the `var` keyword. | ||
|
||
```swift | ||
var variableName = 10 | ||
``` | ||
|
||
Swift is a type-safe, statically typed language, which means all values have a type at compile time. | ||
You can either explicitly specify the type of a variable or let the compiler [infer the type][type-infering] based on the assigned value. | ||
|
||
When assigning a value to a variable are there two ways either through explicit typing through [type annotations][type annotations] or implicit typing. | ||
|
||
```swift | ||
var explicitVar: Int = 10 // Explicitly typed | ||
var implicitVar = 10 // Implicitly typed | ||
``` | ||
|
||
Updating a variable's value is done using the `=` operator. | ||
|
||
````exercism/note | ||
The type of a variable, is fixed once it is initially defined. | ||
```swift | ||
variableName = 13 // update to new value | ||
// compiler error when assigning a different type | ||
variableName = "Hello, world!" // Cannot assign value of type 'String' to type 'Int' | ||
``` | ||
```` | ||
|
||
Variables may be declared without assigning a value by specifying the name and type, but they may not be used before a value is assigned. | ||
|
||
```swift | ||
var someInt: Int | ||
|
||
// This would trigger a compiler error | ||
// print(someInt) // Variable 'someInt' used before being initialized | ||
|
||
// Assign a value to the names | ||
someInt = 169 | ||
|
||
print(someInt) // Prints '169' | ||
``` | ||
|
||
### Constants | ||
|
||
[Constants][constants-variables] are similar to variables in that they are associated with a name and a value, but the value of a constant cannot be changed once it is initially assigned and is thereby _immutable_. | ||
Constants are defined using the `let` keyword. | ||
|
||
```swift | ||
let constantName = 10 // constant | ||
let explicitConstant: Int = 10 // Explicitly typed constant | ||
``` | ||
|
||
### Addition & Subtraction & Multiplication | ||
|
||
Swift has [operators][operators] for addition, subtraction, and multiplication. | ||
The operators are `+`, `-`, and `*` respectively. | ||
|
||
```swift | ||
print(1 + 1) // Prints 2 | ||
print(2 - 1) // Prints 1 | ||
print(2 * 2) // Prints 4 | ||
``` | ||
|
||
### Functions | ||
|
||
In Swift, [functions][functions] are a chunk of code that performs a task. | ||
A function has a return type and can thereby be used as a value and be parsed as arguments to other functions. | ||
In Swift are functions defined using the `func` keyword followed by the name of the function, arguments separated by commas, and a return type. | ||
|
||
The arguments are defined by an argument label, a parameter name followed by a semi-colon and then a type. | ||
The return type is defined by a `->` followed by the type of the return value. | ||
|
||
```swift | ||
func functionName(argumentName parameterName: ArgumentType) -> ReturnType { | ||
// function body | ||
} | ||
``` | ||
|
||
Swift arguments are a bit special compared to other languages, they use [argument labels][argument labels]. | ||
The argument label is used when calling the function. | ||
The parameter name is used inside the function body to refer to the argument value. | ||
If you only assign one name to the argument it will be used as both the argument label and the parameter name. | ||
When assigning the argument label name as: `_` so will the argument not have a label when calling the function, e.g: `functionName(argumentValue)` | ||
|
||
To call a function you use the function name followed by the argument label and the argument value, like this: | ||
|
||
```swift | ||
func functionName(argumentLabel parameterName: ArgumentType) -> ReturnType { | ||
// function body | ||
} | ||
|
||
// calling the function | ||
functionName(argumentLabel: argumentValue) | ||
``` | ||
|
||
All arguments are immutable by default and can't be changed inside the function. | ||
When a function has a return type most be sure to return a value of that type. | ||
That is done by using the `return` keyword followed by the value to return. | ||
|
||
```swift | ||
func addTen(number value: Int) -> Int { | ||
return value + 10 | ||
} | ||
|
||
// calling the function | ||
addTen(number: 10) // Returns 20 | ||
``` | ||
|
||
When functions don't return a value they have a return type of `Void`, which is the same as `()`, but the return type can also be omitted in these cases. | ||
|
||
### Comments | ||
|
||
Swift supports two types of [comments][comments]. | ||
Single line comments are preceded by `//` and multiline comments are inserted between `/*` and `*/`. | ||
|
||
[comments]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Comments | ||
[constants-variables]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Constants-and-Variables | ||
[type annotations]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Type-Annotations | ||
[type-infering]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Type-Safety-and-Type-Inference | ||
[functions]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Defining-and-Calling-Functions | ||
[arithmetical-operators]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/basicoperators/#Arithmetic-Operators |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
[ | ||
{ | ||
"url": "https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html", | ||
"description": "The Basics of Swift" | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/", | ||
"description": "A Swift Tour" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/", | ||
"description": "Swift language guide" | ||
}, | ||
{ | ||
"url": "https://www.swift.org/documentation/", | ||
"description": "Swift language documentation" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Constants-and-Variables", | ||
"description": "Swift language guide: constants and variables" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Defining-and-Calling-Functions", | ||
"description": "Swift language guide: functions" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Type-Annotations", | ||
"description": "Swift language guide: type annotations" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics#Type-Safety-and-Type-Inference", | ||
"description": "Swift language guide: type inferring" | ||
}, | ||
{ | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#Comments", | ||
"description": "Swift language guide: comments" | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.