The difference between a variable declaration and a definition in Swift

The terms "declaration" and "definition" are used synonymously in the Apple Swift documentation, and this confuses me.

In the Initialization section (which talks about class initializers), Apple states:

You can set the initial value for the stored property in the initializer or assign a default property value as part of the property definition .

Further in the subsection they indicate:

You can set the initial value of the saved property from the initializer, as shown above. Alternatively, specify the default property value as part of the Ad properties .

I thought the declaration of a variable was different from the definition of a variable.

+4
source share
4 answers

After a long search on the Internet for legitimate explanations, I seem to have found the answer:

The problem is that the two terms partially overlap. Definitions also serve as declarations because they introduce an identifier of a certain type into scope. However, the declaration is not a definition because it does not entail the allocation of storage for the declared object. To add to the confusion, the semantics of definitions and declarations are slightly different when applied to types and functions, as I will show for a moment. So let's look at a more detailed analysis of these two terms.

Here is the article: Declarations and Definitions .

The article provides additional explanations and examples.

+2

, , , , , AppleDocs. :

: . - , ; , ; , . -, , , . , , undefined .

+2

, var\funct\struct . , , . , , .

+1

, Apple Swift 4 . Declarations ():

. , , , , , , . , .

Swift , , . , , . , , .

0
source

Source: https://habr.com/ru/post/1599231/


All Articles