Avoid creating a shadow variable when array or dictionary element is assigned

Description

In this sample: http://swiftify.me/br6rx1
+1) a shadow `dictionary` variable should not be created when a dictionary element (but not the `dictionary` variable itself) was assigned;
+2) an `inout` keyword should be added to method or function definitions;
+3) an `&` operator should be used when calling such a method (or function) with `inout` parameter;
+4) declare method or function parameters of mutable collection types as non-optional (i.e. `[AnyHashable : Any]`), since we use non-optional initializers for variables of mutable collection types.

+5) As the consequence of (4), the variable `dictionary` should not be unwrapped.

Objective-C:

Converted:

Expected:

List of affected types:

NSMutableString, NSMutableDictionary, NSMutableArray, NSMutableSet, NSMutableIndexSet, NSMutableURLRequest, NSMutableData, NSMutableCharacterSet

Environment

None

Activity

Show:
Ivan Kh
July 19, 2019, 1:44 PM
Edited

+

 

Missed reference in converted swift code: foo(s) → foo(&s)

 

 

Assignee

Alex Petuschak

Reporter

Ivan Kh

Labels

None

Git Branch Name

Feature/AvoidCreatingShadowVariable

GitHub Issue

None

Components

Fix versions

Priority

High
Configure