What you've shown from that presentation isn't an implementation detail. It is the public init
method of VStack
. Note that it doesn't have a method body—it is not the implementation of the init
method, only its type signature.
You can find the same information linked from the VStack
documentation under the “Creating a Stack”?target. Here's the documentation page for that init
method.
You can also see method signatures like this, with doc comments if there are any, in Xcode.
In Xcode 11, choose File > Open Quickly… from the menu bar (default shortcut: ??O). Type “swiftui” in the Open Quickly bar:
Open “SwiftUI.h”. It doesn't say much:
// Copyright ? 2015 Apple Inc. All rights reserved.
#import <AppKit/AppKit.h>
Now click the Related Items icon in the top left corner of the editor and choose Generated Interface > SwiftUI from the menu:
Then, click on “No Selection” to the right of “SwiftUI” in the jump bar at the top of the editor and type “vstack” while the jump menu is open:
Xcode jumps to the definition of struct VStack
:
/// A view that arranges its children in a vertical line.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct VStack<Content> where Content : View {
/// Creates an instance with the given `spacing` and Y axis `alignment`.
///
/// - Parameters:
/// - alignment: the guide that will have the same horizontal screen
/// coordinate for all children.
/// - spacing: the distance between adjacent children, or nil if the
/// stack should choose a default distance for each pair of children.
@inlinable public init(alignment: HorizontalAlignment = .center, spacing: Length? = nil, content: () -> Content)
/// The type of view representing the body of this view.
///
/// When you create a custom view, Swift infers this type from your
/// implementation of the required `body` property.
public typealias Body = Never
}
Unfortunately, this (synthesized) declaration omits the @ViewBuilder
attribute on the content
argument. This omission is probably a bug.
In addition to omitting annotations, Swift's generated interface also omits types, methods, and properties that start with _
. (It omits these because they are considered implementation details that for whatever reason have to be made public.) For example, notice that the generated interface of VStack
also doesn't mention that VStack
conforms to View
. (The reference documentation also doesn't mention it.)
The reason that both the generated interface and the reference documentation don't tell us VStack
conforms to View
is because VStack
doesn't conform directly to View
. VStack
conforms to _UnaryView
, and _UnaryView
is a subprotocol of View
.
You can see the real, honest-to-dog public interface of VStack
—what the compiler actually uses when your source code imports SwiftUI—by tracking down the .swiftinterface
file for the module. You can find it at this path, relative to your Xcode.app
:
Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64.swiftinterface
(So, put /Applications/Xcode-beta.app/
on the front of that path if you haven't renamed the Xcode 11 beta and have it in /Applications
).
If you search that file for struct VStack
, you'll find the true public interface of VStack
:
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
@_fixed_layout public struct VStack<Content> : _UnaryView where Content : SwiftUI.View {
@usableFromInline
internal var _tree: _VariadicView.Tree<_VStackLayout, Content>
@inlinable public init(alignment: HorizontalAlignment = .center, spacing: Length? = nil, @SwiftUI.ViewBuilder content: () -> Content) {
_tree = .init(
root: _VStackLayout(alignment: alignment, spacing: spacing), content: content())
}
public static func _makeView(view: _GraphValue<VStack>, inputs: _ViewInputs) -> _ViewOutputs
public static func _makeViewList(view: _GraphValue<VStack>, inputs: _ViewListInputs) -> _ViewListOutputs
public typealias Body = Swift.Never
}
Note that the .swiftinterface
file does not consolidate extensions. VStack
doesn't have any extensions, but (for example) Color
does, so if you want to see the true public interface of Color
, you need to search for both struct Color
and extension Color
.