variable was written, but never read? variable was written, but never read? xcode xcode

variable was written, but never read?


As error says variable 'isTaken' was written to, but never read means you are creating isTaken instance and assigning a value to it but it never used.


Just eliminate the statements:

var isTaken: Bool = falseisTaken = true

Since the value is never used, defining and assigning to it accomplishes nothing.


Basically it's saying that isTaken is assigned a value, but it doesn't actually do anything in your code. You are never using it or checking it's value, so it's simply an warning saying that the variable is unnecessary.

If you actually are using isTaken and the compiler doesn't realize for some reason, you could probably just add another line right after

isTaken = true;

that just says

isTaken;

Or make isTaken global if you're using somewhere else in the code.