The section about collections in the language guide explains that if you want to reassign a variable that stores an array with an empty array, the compiler can infer the type:
Alternatively, if the context already provides type information,
such as a function argument or an already typed variable or constant,
you can create an empty array with an empty array literal, which is
written as [] (an empty pair of square brackets):
someInts.append(3)
// someInts now contains 1 value of type Int
someInts = []
// someInts is now an empty array, but is still of type [Int]
For completeness/symmetry, I believe it would be nice to say the equivalent for the other two types covered in that section: sets and dictionaries.
If this documentation was open source, I would be glad to contribute a patch myself, but I've been told it is not, so filling a bug.
Please, let me know if documentation suggestions should go somewhere else.
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: c7a570afae42c961a0d834e82f6cfe5fIssue Description:
The section about collections in the language guide explains that if you want to reassign a variable that stores an array with an empty array, the compiler can infer the type:
For completeness/symmetry, I believe it would be nice to say the equivalent for the other two types covered in that section: sets and dictionaries.
If this documentation was open source, I would be glad to contribute a patch myself, but I've been told it is not, so filling a bug.
Please, let me know if documentation suggestions should go somewhere else.