Tom Grounds Tom Grounds - 2 months ago 11
Swift Question

increment Error in swift 3

Hello I am using swift and when I am trying to use and increment it outputs a pair of parenthesis.

var initialScore = 8
let TotalScore = initialScore+=1


The error comes out as

Constant 'TotalScore' inferred to have type '()', which may be unexpected

Please help me!

Answer

You have small issue that is connected with =. To solve youre problem try :

var initialScore = 8
let TotalScore = initialScore+1

If you would like to increment value by 1 you should not use = before 1 in you're case.

Small example where you should use += together.

var a = 1
a += 2