How to disable automatic modification of struct to enum in my code

I used struct in the swift file, but once I use xcode build. It will automatically change to enum, causing build failure. But it turns out that this file can be used to build. Since upgrading to XCode16.1, it's not working anymore. I don't know where to set it up. Do not optimize or modify my code.

Error message: 'Padding' cannot be constructed because it has no accessible initializers

My environment is: macos sequoia 15.1 xcode 16.1(16B40)

File source code:


let π: CGFloat = .pi
let customUserAgent: String = "litewallet-ios"
let swiftUICellPadding = 12.0
let bigButtonCornerRadius = 15.0

enum FoundationSupport {
    static let dashboard = "https://support.litewallet.io/"
}

enum APIServer {
    static let baseUrl = "https://api-prod.lite-wallet.org/"
}

enum Padding {
    subscript(multiplier: Int) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }

    subscript(multiplier: Double) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }
}

enum C {
    static let padding = Padding()
    enum Sizes {
        static let buttonHeight: CGFloat = 48.0
        static let sendButtonHeight: CGFloat = 165.0
        static let headerHeight: CGFloat = 48.0
        static let largeHeaderHeight: CGFloat = 220.0
    }

    static var defaultTintColor: UIColor = UIView().tintColor

Enum was originally SRTUCT. But the build has been automatically optimized

Answered by DTS Engineer in 812424022

I think you’ve misunderstood what’s going on here. None of our tools will automatically convert your struct to an enum. The code you’ve posted clearly shows an enum, Padding, and that enum is the source of the error you posted [1].

If you change enum Padding to struct Padding, your code should compile.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] An enum with no members can’t be created, and thus you can’t have a subscript on it.

I think you’ve misunderstood what’s going on here. None of our tools will automatically convert your struct to an enum. The code you’ve posted clearly shows an enum, Padding, and that enum is the source of the error you posted [1].

If you change enum Padding to struct Padding, your code should compile.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] An enum with no members can’t be created, and thus you can’t have a subscript on it.

I swear he changed it during the build process. Please see the video I recorded, the source code is

    static let dashboard = "https://support.litewallet.io/"
}

struct APIServer {
    static let baseUrl = "https://api-prod.lite-wallet.org/"
}

struct Padding {
    subscript(multiplier: Int) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }

    subscript(multiplier: Double) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }
}

struct C {
    static let padding = Padding()
    struct Sizes {
        static let buttonHeight: CGFloat = 48.0
        static let sendButtonHeight: CGFloat = 165.0
        static let headerHeight: CGFloat = 48.0
        static let largeHeaderHeight: CGFloat = 220.0
    }

    static var defaultTintColor: UIColor = UIView().tintColor

    static let animationDuration: TimeInterval = 0.3
    static let secondsInDay: TimeInterval = 86400
    static let maxMoney: UInt64 = 13_500_000_000 * 100_000_000
    static let satoshis: UInt64 = 100_000_000

video:https://youtu.be/igPREnWpqL4

Since you intend to use Padding as a type that can be instantiated, you should define it as a struct instead of an enum. Here’s how you can modify your definition

struct Padding {
    subscript(multiplier: Int) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }

    subscript(multiplier: Double) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }
}

Also, If you want to keep it as an enum for some reason, you'll need to define cases for it or remove the static instance creation (static let padding = Padding()). However, since you want to avoid modifying your code significantly, changing it to a struct is the most straightforward solution.

Also, If you want to keep it as an enum for some reason, you'll need to define cases for it or remove the static instance creation (static let padding = Padding()). However, since you want to avoid modifying your code significantly, changing it to a struct is the most straightforward solution.

Please see the video I recorded

Well, that certainly is weird. I’m not aware of any way that Xcode will do that by itself. I suspect that there’s something specific to your setup that’s causing this. Perhaps:

  • There’s something about your Mac’s setup that’s changing the file. For example, I’ve seen folks run into problems when their project is in a directory managed by a file provider (iCloud Drive, Dropbox, and so on).

  • It’s also possible that something in your project is causing this.

As a first step I recommend that you rule out any environmental causes. If you create a ‘clean’ Mac and build your project there, does it have the same problem?

I usually do this sort of testing in a VM, so that I can restore to a clean snapshot between each test. If you can’t do that for some reason, a much simpler test is to create a new local user account (in System Settings > Users & Groups) and retry there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

This is a local project and does not use cloud storage. I just don't understand where XCode is set up.

@Hemanth.Alluri Thank you very much for your help in responding. Please take a look at the video

My source code contains struct, but after XCode build, the struct in my source code was modified to an enum, causing an error. Unable to successfully buiild.

My source code is

    subscript(multiplier: Int) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }

    subscript(multiplier: Double) -> CGFloat {
        return CGFloat(multiplier) * 8.0
    }
}

Is your project configured (by someone) to run a linter as a build step?

If so, is that linter performing auto corrections? (Yikes!)

And if so, is that linter triggering on your structs that contain no instance properties?

(I’m familiar with SwiftLint which has a rule that suggests changing struct to enum when there are only static properties, but it doesn’t trigger on your Padding struct. Maybe a different linter does something similar but goes wrong in your case.)

Accepted Answer

The reason has been found!!! It should be using GitHub desktop. After repeated testing. It's because of the GitHub desktop.

How to disable automatic modification of struct to enum in my code
 
 
Q