tinymind / LSUnusedResources

A Mac App to find unused images and resources in Xcode project.
MIT License
4.16k stars 717 forks source link

False positives due to SwiftGen provided assets #32

Closed drjasonharrison closed 7 years ago

drjasonharrison commented 7 years ago

We have image assets that are referenced in code as Asset.imageName.image. The list of image assets is generated using SwiftGen using the following command as a build phase:

 swiftgen images "$PROJECT_DIR/appname/Assets.xcassets" -t swift3 \
--output "$PROJECT_DIR/appname/Constants/Images.swift"

If LSUnusedResources had access to Images.swift it would have the mapping between image filename and code Asset.imageName:

enum Asset: String {
  case bgBluetooth = "bg-bluetooth"
  case addFab = "add_fab"
  case arrowRight = "arrow_right"
  case batteryLow = "battery_low"
 ....

And then LSUnusedResources could search the source code for "Asset." and then for one of image names.

tinymind commented 7 years ago

Hi, please try to change swift patterns from @"(.+?)" to "(.+?)".

image

drjasonharrison commented 7 years ago

Yes! that fixes the problem with the false positives! Thank you! Can you please explain how the @ symbol is being used in the regular expression? As a the Objective-C escape for NSString literals, or as a PERL array?

tinymind commented 7 years ago

The regular expression is used to match string in source code. In Objective-C, string constants start with @, like NSString *str = @"background";. But in swift, string constants don't need the @ symbol.