gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ambiguous use of 'frame'.

tskwara opened this issue · comments

Guille-

I'm running into an 'Ambiguous use of 'frame' build error. Your View extension has frame overloads that all look right, but for some reason Xcode is having trouble disambiguating between the base initializes and yours.

-Tom

Hi @tskwara,

Can you provide a code snippet to reproduce the issue? Also, please confirm that you are using the gfm-and-swiftui-native-rendering branch (currently work in progress).

Issue

I'm defining my own ElementTypeView custom SwiftUI view struct. In this snippet, my custom view includes a standard frame modifier to set the horizontal alignment in that view. This issue comes up even when using a standard Text struct and a frame modifier. When typing in the frame modifier, Xcode suggests different initializers, all of which are only yours and not the standard SwiftUI initializers. So it seems your extension of View to have frame modifiers that use the Size type ends up replacing all standard frame modifier implementations. I only see yours that are based on your Size type.

Perhaps you don't see this issue since your example is embedded in the same project as the framework, as opposed to including the framework as an external package.

In my code, I only did two things to now have this error: 1) add the MarkdownUI package dependency to the project; and 2) Add import MarkdownUI line in my source file. No other changes made.

Here is a link to details on what appears to be a wider Swift issue with regards to extensions in modules:
https://forums.swift.org/t/ambiguous-use-of-a-same-name-var-or-func-of-extension-from-different-modules/58306

Also note, I am using the gfm-and-swiftui-native-rendering branch when this issue shows up. Using the main branch does not result in the issue.

Thanks for the clarification. I guess I will need to rename those methods to avoid ambiguity.

That's unfortunate, but may not be avoidable. Maybe sizedFrame? There's probably the same issue with padding and lineSpacing overloads in the same View extension.

Hey @tskwara, I believe this PR fixes the issue: #180.
Let me know otherwise and thanks for trying out the gfm-and-swiftui-native-rendering branch!

@gonzalezreal Sorry for the delay, buy I just tested the updated code and the issue is still present. I don't believe the ambiguity is with the parameter names, but rather with using the frame, padding, and relativeLineSpacing function names. They have the same name as the SwiftUI versions, and that is the ambiguity resulting in the error. You can reproduce this issue by doing the following:

  1. Create a new SwiftUI project.
  2. Add the MarkdownUI package dependency, and use the gfm-and-swiftui-native-rendering branch.
  3. In the sample ContentView struct, add import MarkdownUI.
  4. In the sample ContentView struct, add a frame modifier and specify something like alignment as shown below.
  5. Build the app and observe the ambiguous error and suggested candidates.
//
//  ContentView.swift
//  test
//
//  Created by Tom Skwara on 1/15/23.
//

import SwiftUI
import MarkdownUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .frame(alignment: .trailing)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Fixed in #181, this time for good.