Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift doesn't generate unused variable warning

In Objective-C, the following code generates Unused variable warning:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSInteger unusedVariable;
}

But in Swift, the following same code does not generate the warning:

override func viewDidLoad() {
    super.viewDidLoad()

    var unusedVariable: Int
}

Xcode version is 6.0.1.
Build Settings > Unused Variables is YES in Swift project.

Is this happening only to me?
How to make Swift or Xcode generate Unused variable warning in Swift?

like image 272
user_ Avatar asked Oct 01 '14 10:10

user_


1 Answers

According to Chris Lattner's post on the Apple Developer Forums, this is still a bug:

It's a known issue, we have a radar for it, thanks!

-Chris

Update: Not only does Swift now have unused variable warnings, it also is also yells at you when you use a var where a let would suffice.

like image 69
erdekhayser Avatar answered Nov 20 '22 00:11

erdekhayser