Inside an iOS SwiftUI project, It compiles but fail to run with this error:
found an unexpected second identifier in function declaration; is there an accidental break?
extension View {
@ViewBuilder func `if`<T>(_ condition: Bool, transform: (Self) -> T) -> some View where T : View {
if condition {
transform(self)
} else {
self
}
}
}
This code is from: Conditionally apply modifier in SwiftUI - #17 by bzamayo
Same with my little test:
import SwiftUI
enum Bar {
static func `default`(value: Int) -> Int {
value + 1
}
}
struct UserDefaultBackTick: View {
var body: some View {
Text("\(Bar.default(value: 100))")
}
}
struct UserDefaultBackTick_Previews: PreviewProvider {
static var previews: some View {
UserDefaultBackTick()
}
}
swiftc the following is fine:
enum Bar {
static func `default`(value: Int) -> Int {
value + 1
}
}
print(Bar.default(value: 100))