'Extension function is inaccessible due to 'internal' protection level
So I have this lovely extension that would allow me to write conditional view modifiers to my views, made by Antoine van der Lee https://www.avanderlee.com/swiftui/conditional-view-modifier/. The problem I'm running into is that it is inaccessible because of 'internal' protection level, even though I have set the extension AND the function public. Any ideas how to fix this that doesn't involve pasting it to all the files.?
import SwiftUI
public extension View {
/**
Applies the given modifier if the given condition evaluates to `true`.
- Parameters:
- condition: The condition to evaluate.
- transform: The modifier to add to the source `View`.
- Returns: Either the original `View` or the modified `View` if the condition is `true`.
*/
@ViewBuilder
public func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
if condition() {
transform(self)
} else {
self
}
}
}
The extension is also in it's own package that is being imported to the package with my views.
Usage in code:
Text("Hello, world!")
.padding()
.if(image != nil) { view in
view.padding()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
