A
A
azwg2021-10-13 01:44:54
Swift
azwg, 2021-10-13 01:44:54

Error in Xcode “invalid redeclaration of str, how to fix or what is the reason?

Hello, I apologize in advance for the stupid question.

I study quietly Xcode, I take one course on YouTube.

The presenter has an expression

var str = "text"

However, I get an error invalid redeclaration of str

What could be the problem?

If you write var str1 - there is no error, but as I understand it correctly - the variable str1 is being assigned

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
briahas, 2021-10-13
@briahas

you most likely declared a variable with the same name twice.
By declaring a variable I mean a construction of the form:var someName = ...

V
Vladislav Resly, 2021-12-10
@Resly34

That's right, you are creating the "str" ​​variable at a time when you have already created this variable.
If you want to change the str variable, then you need to remove "var", because this keyword creates a variable
, or, if you still want to create a variable, then you need to specify a name that was not previously used in the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question