Errors and Warnings !!? Checkout and fix, if that got listed here.

1. Error: Cannot use mutating member on immutable value: ‘shoppingList’ is a ‘let’ constant

Sample Code:

Error: Cannot use mutating member on immutable value: ‘shoppingList’ is a ‘let’ constant
Solution: Cannot use mutating member on immutable value shoppingList is a let constant

2. Error: Empty collection literal requires an explicit type

Sample Code:

Empty collection literal requires an explicit type
Solution 1: Empty collection literal requires an explicit type
Solution 2: Empty collection literal requires an explicit type

3. Error: Use of unresolved operator ‘++’; did you mean ‘+= 1’?

Sample Code:

Use of unresolved operator ‘++’; did you mean ‘+= 1’
  • & — operators are removed in advanced version of swift, You can use += 1 and -= 1 etc.. to perform the addition, subtraction or multiple the actual variable with some value.
Solution: Use of unresolved operator ‘++’; did you mean ‘+= 1’

4. Error: ‘nil’ cannot initialize specified type ‘String’

Sample Code:

‘nil’ cannot initialize specified type ‘String’
Solution: ‘nil’ cannot initialize specified type ‘String’

5. Warning: Left side of nil coalescing operator ‘??’ has non-optional type ‘String’, so the right side is never used

Sample Code:

Left side of nil coalescing operator ‘??’ has non-optional type ‘String’, so the right side is never used
Solution: Left side of nil coalescing operator ‘??’ has non-optional type ‘String’, so the right side is never used

6. Error: Switch must be exhaustive

Sample Code:

Switch must be exhaustive
Solution: Switch must be exhaustive

7. Error: Anonymous closure argument not contained in a closure

Sample Code:

Anonymous closure argument not contained in a closure
Solution: Anonymous closure argument not contained in a closure

8. Warning: String interpolation produces a debug description for an optional value; did you mean to make this explicit?

Sample Code:

String interpolation produces a debug description for an optional value; did you mean to make this explicit?
Solution 1: String interpolation produces a debug description for an optional value
Solution 2: String interpolation produces a debug description for an optional value

9. Error: Cannot force unwrap value of non-optional type ‘String’

Sample Code:

Cannot force unwrap value of non-optional type ‘String’
Solution: Cannot force unwrap value of non-optional type ‘String’

10. Error: Variable ‘nameOfVariable’ used before being initialized

Sample Code:

Variable ‘nameOfVariable’ used before being initialized
Solution: Variable ‘nameOfVariable’ used before being initialized

11. Error: Left side of mutating operator isn’t mutable: ‘self’ is immutable

Sample Code:

Left side of mutating operator isn’t mutable: ‘self’ is immutable
Solution: Left side of mutating operator isn’t mutable: ‘self’ is immutable

12. Error: Type ‘Int’ does not conform to protocol ‘ExampleProtocol’

Sample Code:

Type ‘Int’ does not conform to protocol ‘ExampleProtocol’

13. Error: Extensions must not contain stored properties

Sample Code:

Extensions must not contain stored properties
Solution: Extensions must not contain stored properties

14. Error: Missing return in a function expected to return ‘String’

Sample Code:

Missing return in a function expected to return ‘String’
Solution: Missing return in a function expected to return ‘String’

15. Error: Computed property must have an explicit type

Sample Code:

Computed property must have an explicit type
Solution: Computed property must have an explicit type

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store