Warning: color asset name resolves to a conflicting Color symbol

I have created a IOS Application in XCode 15.2 (15C500b) which causes issue not able to see previews.

In the Assets.xcassets folder I have created a ThemeColors which contains 5 Color Sets. I had used these in another Swift Project, and also used these same color sets in the second project. The First Project name was WC. The Second Project name is WCCardDemo stored in a different project folder.

Now when I copy or retype these color sets into the Project WCCardDemo, I get the following warnings in

Multiline

^ WCCardDemo X Command compiledAssetCatalog failed with nonzero exit code

  • The "GreenColor" color asset name resolves to a conflicting UI symbol "green. Try renaming the asset.

  • The "RedColor" color asset name resolves to a conflicting UI symbol "red. Try renaming the asset.

BlockQuote

When I try to refresh the startup default ContentView I get Failed to build the scheme WC

Content View

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color.theme.background.ignoresSafeArea()
            
            VStack {
                Text("Accent Color")
                    .foregroundColor(Color.theme.accent)
                Text("Seconday Text Color")
                    .foregroundColor(Color.theme.secondaryText)
                Text("Red Color")
                    .foregroundColor(Color.theme.red)
                Text("Green Color")
                    .foregroundColor(Color.theme.green)
                
            }
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
code-block

I also get the GeneratedAssetSymbols file displayed !! <GeneratedAssetSymbols.swift>

...
extension DeveloperToolsSupport.ColorResource {
...

    /// The "BacktgroundColor" asset catalog color.
    static var backtground: UIKit.UIColor {
#if !os(watchOS)
        .init(resource: .backtground)
#else
        .init()
#endif
    }

    #warning("The \"GreenColor\" color asset name resolves to a conflicting UIColor symbol \"green\". Try renaming the asset.")

    #warning("The \"RedColor\" color asset name resolves to a conflicting UIColor symbol \"red\". Try renaming the asset.")
code-block

This appears to me to be xCode bug, and not a coding issue. I am asking if reusing assets and color sets File names in multple swift projects is bad practice. This does not make sense to me, that I can not reuse color set files ???. The first time I used the RedColor colorset name it was no issue. If i use it again in another separate Swift Project I get compile errors ??? Clean project does not fix this issue.

Thanks in Advance for any Information of best pratices, or what issue I am having.

Answered by bxw0405 in 778072022

I found an explanation on Hacking With Swift website. This web site is for Learning Swift and as far as I can see, it is a safe website which provided the solution to my issue. I am not able to post that link here.

In my case the warning is destructive and causes runtime issues and also issue with the preview failing I have set flag to false and this appears to have resolved this runtime issue.

What I read is this appears to be a feature added in xCode 15. This setting is found under Asset: Catalog Compiler - Options The switch is Generate Asset Symbols = false. It has a default of yes.

When I have more time I will look deeper into this feature. I would have issues in my development style, if this was not a build setting.

Thanks for any more details, if you happen to know more about this feature..

Accepted Answer

I found an explanation on Hacking With Swift website. This web site is for Learning Swift and as far as I can see, it is a safe website which provided the solution to my issue. I am not able to post that link here.

In my case the warning is destructive and causes runtime issues and also issue with the preview failing I have set flag to false and this appears to have resolved this runtime issue.

What I read is this appears to be a feature added in xCode 15. This setting is found under Asset: Catalog Compiler - Options The switch is Generate Asset Symbols = false. It has a default of yes.

When I have more time I will look deeper into this feature. I would have issues in my development style, if this was not a build setting.

Thanks for any more details, if you happen to know more about this feature..

What happens if you rename RedColor to HorseBatteryStapleColor?

If the horse colour doesn't error, it's probably because UIColor.redColor is an actual thing and you're trying to overwrite it, but UIColor.horseBatteryStapleColor isn't a UIColor object so Xcode looks in your asset catalog.

Just rename your colours to something more descriptive such as RedColor --> BadColor and GreenColor --> GoodColor.

It works and no more issues. My current design is to reuse the RedColor so that I can maximize color set names. It is a design pattern. I wanted to reuse this simple name so that all applications might have access to these various color schemes. I suggest it is an ok design pattern to reuse color sets. I have a Color.swift extension that uses this name, and it allows me to write faster code and reuse these designs thruout my code base.

I am a new Swift developer so it took my several hours to figure this out. I think this feature was added in 15.0

Warning: color asset name resolves to a conflicting Color symbol
 
 
Q