Quick Answer

Attempting to change a let-declared constant

Understanding the Issue

Swift constants declared with let are immutable. This error occurs when trying to modify them after initialization.

The Problem

This code demonstrates the issue:

Swift Error
// Problem: Modifying constant
let count = 5
count += 1 // Error

The Solution

Here's the corrected code:

Swift Fixed
// Solution 1: Use var if mutable
var count = 5
count += 1

// Solution 2: Create new value
let count = 5
let newCount = count + 1

Key Takeaways

Use let for constants and var for variables that need to change.