Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift 2.0 Basics Swift Operators Working With Operators: Part 2

Deepesh Madkar
Deepesh Madkar
1,507 Points

"++" are removed from swift 3, got this message in xcode.

This is giving error in swift 3: let totalScore = ++initialScore

so is this the right way: let totalScore = initialScore + 1

operators2.swift
// Enter your code below

var initialScore = 8
let totalScore = ++initialScore

1 Answer

Miles Ranisavljevic
Miles Ranisavljevic
3,591 Points

You are partially correct - if you write

let totalScore = initialScore + 1

you will correctly make totalScore 9 (in the example), but you're not doing the other part of the old ++initialScore which is that ++ also increments the variable, making initialScore = 9 as well. So the fastest way of doing this would be something like this:

var initialScore = 8
initialScore += 1 //This is the short way of saying: initialScore = initialScore + 1
let totalScore = initialScore

That would increment initialScore, and then assign that value (9) to the constant totalScore.