Skip to content

PauloSTDev/basic_swift

Repository files navigation

swift

Variables and Values Assignments

We can assign any values to ours variables, example: String, Int, Double. But when we assign the type of a variable, we can not change anymore, in other words, if you create a variable with the type string, it will be a string forever

Naming Variables (Mutable and Constants)

We can create variables with typing or without typing

Mutables

We can change the values assignment

Without typing (Type Inference):

  • var mutableVariableString = "Paulo Santos"

  • var mutableVariableInt = 20

  • var mutableVariableDouble = 10.5

  • var mutableVariableBool = true

With typing (Type Annotations):

  • var mutableVariableString: String = "Paulo Santos"

  • var mutableVariableInt: Int = 20

  • var mutableVariableDouble: Double = 10.5

  • var mutableVariableBool: Bool = true

Constants

We can not change the values assignment

Without typing (Type Inference):

  • let constantVariableString = "Without typing"

  • let constantVariableInt = 20

  • let constantVariableDouble = 10.5

With typing (Type Annotations):

  • let constantVariableString: String = "With typing"

  • let constantVariableInt: Int = 20

  • let constantVariableDouble: Double = 10.5

Types

Class

Works with object reference (Reference type)

Struct

Struct is similar to class but the Struct already has a constructor when we initialize it, are independent, use copy of the value (Value Type) and with Struct we can't use heritage but can use protocol implementations. Struct has better performance and Class are more powerful

Multi-line Strings

To get the multi-line strings we need to start and end with three double quote marks.

Captura de Tela 2023-03-06 às 21 54 31

String Interpolation

All we have to do is write a backslash, , followed by your variable name in parentheses

Captura de Tela 2023-03-07 às 15 35 36

📖 Sources:

📔 Swift Documentation: https://www.swift.org/documentation/

📕 Curso de Swift - Programação - Tiago Aguiar: https://www.youtube.com/playlist?list=PLJ0AcghBBWShgIH122uw7H9T9-NIaFpP-

About

Study Project of Language Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages