Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error message in SwiftUI: Type '() -> ()' cannot conform to 'ShapeStyle'

I wrote an extension for the instructions inside the application, after writing an error came out:

Type '() -> ()' cannot conform to 'ShapeStyle'

Here is the extension itself and here is the error:

extension View{
    //MARK: - Custom Spotlight Modefier
    func spotlight(enabled: Bool, title: String = "")->some View{ 
        return self  //Error Message: Type '() -> ()' cannot conform to 'ShapeStyle'
            .overlay{
                if enabled{
                    //To Get the Current Content Size
                    GeometryReader{proxy in
                        let rect = proxy.frame(in: .global)
                        
                        SpotlightView(rect: rect, content: title){
                            self
                        }
                    }
                }
            }
    }
    
    //MARK: - Screen Bounds
    func screenBound()->CGRect{ }

    //MARK: - Root Controller
    func rootController()->UIViewController{ }
}

The structure that is needed to display instructions

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

struct SpotlightView<Content: View>: View{
    var content: Content
    var title: String
    var rect: CGRect

    init(rect: CGRect ,title: String, @ViewBuilder content: @escaping ()->Content){
        self.content = content()
        self.title = title
        self.rect = rect
    }

    @State var tag: Int = 1009

    var body: some View{
        Rectangle()
            .fill(.white.opacity(0.02))
            .onAppear {
                addOverlayView()
            }
            .onDisappear{
                removeOverlayView()
            }
    }

    //MARK: - Removing the overlay when over view disappeared
    func removeOverlayView(){ }

    //MARK: - Adding An Extra View over the Current View
    func addOverlayView(){ }

    @ViewBuilder
    func overlaySwiftUIView()->some View{ }

    //MARK: - Random Number for Tag
    func generateRandom()->Int{ }

>Solution :

In your extension to View, in this line SpotlightView(rect: rect, content: title) you are not matching your initialiser. The SpotlightView requires 3 parameters:

  • rect, of type CGRect
  • title, of type String
  • content, a closure

You are providing:

  • rect, of type CGRect
  • content, of type String
  • a closure

Start by correcting the call to SpotlightView, replacing "content" with "title".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading