A hidden feature or SwiftUI API related bug?

Command click in Xcode 11 (on Catalina) on some types like Button or SwiftUI module in general reveals seemingly broken type aliases such as:

public struct Button<Label> where Label : View {
    public typealias Body
}

extension View {
    /// The type resulting from applying a view modifier `T`.
    public typealias Modified<T>
}

Is this a bug or a hidden feature that the framework required?

Same goes for the online docs:

https://developer.apple.com/documentation/swiftui/button/modified

Why can't we see what the type alias is aliasing here?

I think what you're seeing is the same interface printing behavior that you get for things like PlaygroundQuickLook or AnyObject.

Hmm so they are hiding implementation detail types?

You can't see the types because they are prefixed with _ and Xcode hides such types.

You can find the types in this file:

/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64.swiftinterface

Here is struct Button:

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct Button<Label> : __LegacyView where Label : SwiftUI.View {
  public init(action: @escaping () -> Void, @SwiftUI.ViewBuilder label: () -> Label)
  public var body: _View {
    get
  }
  public typealias Body = SwiftUI._AutoViewWrapper
}

And here is the extension View that defines Modified:

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {
  public typealias Modified<T> = _ModifiedContent<Self, T> where T : SwiftUI.ViewModifier
  @inlinable public func modifier<T>(_ modifier: T) -> Modified<T> where T : SwiftUI.ViewModifier {
        return .init(content: self, modifier: modifier)
    }
}
6 Likes

Cool thank you for sharing where I can check the interface files, that's helpful.

But for some reason this only applies to Apple frameworks and stdlib, I don't recall that this ever worked for custom types that begin with a single underscore.

1 Like