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
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.