Skip to content

Commit 62f2b45

Browse files
committed
toc
1 parent a578c05 commit 62f2b45

File tree

44 files changed

+1829
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1829
-44
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# Learn Swift By Examples
22

3+
[Swift](https://swift.org) is an open-source programming language designed for modern software development. It scales seamlessly from embedded devices and operating system kernels to mobile apps and cloud infrastructure, making it one of the most versatile languages available today.
4+
5+
Swift is simple and expressive, with incredible performance, memory safety, and speed. It offers best-in-class interoperability with C and C++, giving developers access to decades of proven libraries and tooling.
6+
7+
This website is a hands-on introduction to Swift with clear, practical examples. All code snippets run with the latest major Swift release, ensuring compatibility and relevance for real projects.
8+
9+
Start learning Swift today by exploring the examples below and discover why Swift is the language of choice for everything from iOS development to server-side programming.
10+
311
[Learn Swift By Examples](https://learn-swift.com/)

contents/[01]hello-world/index.md renamed to contents/[01]the-print-function/index.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
---
2-
title: "Hello, World!"
2+
title: "The print function"
33
description: ""
44
order: 1
55
---
66

77
The print function displays text or values on the screen. In the simplest form it means we can display messages on the command line. Create a new file named `main.swift` and place the following Swift code inside the file:
88

99
```swift
10-
print("Hello, world!")
10+
// FILE: main.swift
11+
12+
print("Hello, World!")
13+
14+
/**
15+
Run Swift files using the command line:
16+
17+
$ swift main.swift
18+
> Hello, World!
19+
*/
1120
```
1221

1322
Run the program via the `swift main.swift` command, it will display the `Hello, World!` message.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "Constants and variables"
3+
description: ""
4+
order: 2
5+
---
6+
7+
foo
8+
9+
```swift
10+
// a constant
11+
let name: String = "John"
12+
print(name) // => John
13+
14+
name = "Bob" // => ERROR
15+
// Cannot assign to value:
16+
// 'name' is a 'let' constant
17+
18+
// a variable
19+
var age: Int = 42
20+
age = 69
21+
print(age) // => 69
22+
```
23+
24+
bar
25+
26+
```sh
27+
swift main.swift
28+
```
29+
30+
baz

contents/[02]standard-types/index.md

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Standard types"
3+
description: ""
4+
order: 3
5+
---
6+
7+
8+
foo
9+
10+
```swift
11+
let b: Bool = false
12+
13+
let i: Int = 6
14+
15+
let f: Float = 4.20
16+
17+
let d: Double = 6.9
18+
19+
let s: String = "Lorem ipsum"
20+
```
21+
22+
bar
23+
24+
```sh
25+
swift main.swift
26+
```
27+
28+
baz

contents/[03]values/index.md

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: "String operations"
3+
description: ""
4+
order: 4
5+
---
6+
7+
8+
foo
9+
10+
```swift
11+
let name = "John"
12+
let age = 42
13+
let end = "years old."
14+
15+
// String interpolation
16+
print("\(name) is \(age) \(end).")
17+
// => John is 42 years old.
18+
```
19+
20+
bar
21+
22+
```sh
23+
swift main.swift
24+
```
25+
26+
baz

contents/[05]operators/index.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "Operators"
3+
description: ""
4+
order: 5
5+
---
6+
7+
8+
foo
9+
10+
```swift
11+
let x = 5
12+
let y = 5
13+
var z = 0
14+
15+
z = x + y // addition
16+
print(z) // => 10
17+
18+
z = x - y // subtraction
19+
print(z) // => 0
20+
21+
z = x * y // multiplication
22+
print(z) // => 25
23+
24+
z = x / y // division
25+
print(z) // => 1
26+
27+
28+
var x = 10
29+
30+
x += 2 // addition
31+
print(x) // => 12
32+
33+
x -= 2 // subtraction
34+
print(x) // => 10
35+
36+
x *= 2 // multiplication
37+
print(x) // => 20
38+
39+
x /= 2 // division
40+
print(x) // => 10
41+
```
42+
43+
bar
44+
45+
```sh
46+
swift main.swift
47+
```
48+
49+
baz

contents/[06]optionals/index.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "Optionals"
3+
description: ""
4+
order: 6
5+
---
6+
7+
8+
foo
9+
10+
```swift
11+
let x = 5
12+
let y = 5
13+
var z = 0
14+
15+
z = x + y // addition
16+
print(z) // => 10
17+
18+
z = x - y // subtraction
19+
print(z) // => 0
20+
21+
z = x * y // multiplication
22+
print(z) // => 25
23+
24+
z = x / y // division
25+
print(z) // => 1
26+
27+
28+
var x = 10
29+
30+
x += 2 // addition
31+
print(x) // => 12
32+
33+
x -= 2 // subtraction
34+
print(x) // => 10
35+
36+
x *= 2 // multiplication
37+
print(x) // => 20
38+
39+
x /= 2 // division
40+
print(x) // => 10
41+
```
42+
43+
bar
44+
45+
```sh
46+
swift main.swift
47+
```
48+
49+
baz
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "The readline function"
3+
description: ""
4+
order: 7
5+
---
6+
7+
8+
foo
9+
10+
```swift
11+
let x = 5
12+
let y = 5
13+
var z = 0
14+
15+
z = x + y // addition
16+
print(z) // => 10
17+
18+
z = x - y // subtraction
19+
print(z) // => 0
20+
21+
z = x * y // multiplication
22+
print(z) // => 25
23+
24+
z = x / y // division
25+
print(z) // => 1
26+
27+
28+
var x = 10
29+
30+
x += 2 // addition
31+
print(x) // => 12
32+
33+
x -= 2 // subtraction
34+
print(x) // => 10
35+
36+
x *= 2 // multiplication
37+
print(x) // => 20
38+
39+
x /= 2 // division
40+
print(x) // => 10
41+
```
42+
43+
bar
44+
45+
```sh
46+
swift main.swift
47+
```
48+
49+
baz

0 commit comments

Comments
 (0)