Skip to content

Rule Request: Prefer using Asset Symbols #5939

@417-72KI

Description

@417-72KI

New Issue Checklist

New Rule Request

It would be happy when Image that initialized with string replaced with initializer with asset symbols.

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

UIKit.UIImage(named:) and SwiftUI.Image(_:) contain the risk of bugs due to typos.
Since Xcode 15, Xcode generates codes for images in the Asset Catalog and it can avoid typos. (ref)

  1. Provide several examples of what would and wouldn't trigger violations.

Would trigger:

// UIKit
UIImage(named: "some_image") // simple
UIImage(named: "some image")  // contains space
UIImage(named: "someImage", in: .module) // contains specified module

// SwiftUI
Image("some_image") // simple
Image("some image")  // contains space
Image("someImage", bundle: .module) // contains specified module

Would not trigger:

// UIKit
UIImage(resource: .someImage)
UIImage(systemName: "trash")  // using SF Symbols

// SwiftUI
Image(.someImage)
Image(systemName: "trash")  // using SF Symbols
  1. Should the rule be configurable, if so what parameters should be configurable?

Currently no.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a rule as opt-in.

Enabled by default on Swift 5.9+.
Asset symbol generation is enabled by default in Xcode, and it needs editing the build setting to disable it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions