How to Find Actual Swiftui API Documentation (And Not Just the Developer Documentation)

Is there a way to find actual SwiftUI API Documentation (and not just the developer documentation)?

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 quickly bar with swiftui

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:

SwiftUI under Related Items 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:

finding vstack in the jump menu

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.

Where can I see the source code of swiftUI?

SwiftUI isn't included in the Open Source Swift Project, but There Is an undergoing project to build an Open Source implementation of Apple's SwiftUI DSL.
https://github.com/Cosmo/OpenSwiftUI

Where is Self._printChanges() defined and/or documented for SwiftUI?

Unfortunately, _printChanges() is a private API, which is why it's undocumented. The only reason so many videos and articles referenced it is because an Apple engineer mentioned it during WWDC21. Here's what they said:

It's not technically API-notice the leading underscore — so should only be used in debugging. My one sentence pro-tip is the extent of the docs I'm afraid.

Screenshot of chat room

However, Xcode does show a summary when you Option + Click.

Summary

When called within an invocation of body of a view of this type, prints the names of the changed dynamic properties that caused the result of body to need to be refreshed. As well as the physical property names, “@self” is used to mark that the view value itself has changed, and “@identity” to mark that the identity of the view has changed (i.e. that the persistent data associated with the view has been recycled for a new instance of the same type).

SwiftUI Form struct not recognized by Xcode 11

According to the release notes, support for the Form view was added in beta 2, which was released today (6/18/19). Download the latest Xcode beta from Apple and you should be able to use the Form view!

Use of @StateObject in Document-based SwiftUI application: getting instances instead of references

@StateObject is just for Views, try ReferenceFileDocument but before you resort to using classes I highly recommend figuring out if you can stick to structs because Swift and SwiftUI work best with value types. See https://developer.apple.com/documentation/swift/choosing_between_structures_and_classes

RxBluetoothKit documentation?

All of the documentation is written above the methods so while typing discoverServices in Xcode you should be able to click on method with options key and little popup will come up with formatted documentation. Our doc is formatted by the CocoaDocs - it appears that it has some problems. I'm working on fixing it - here you can find the issue Github issue

SwiftUI Documentation for @State property wrapper

As property wrappers were a Swift Evolution proposal and were developed as part of Swift's open source philosophy, we can find the best documentation directly in the Proposal SE-0258 document.
This describes the rationale behind the @propertyWrapper design, and the exact specification to how they are implemented (including the definitions of wrapped values and projected values).

Sections that may help in your understanding:

§ A property wrapper type provides the storage for a property that uses it as a wrapper. The wrappedValue property of the wrapper type provides the actual implementation of the wrapper, while the (optional) init(wrappedValue:) enables initialization of the storage from a value of the property's type.

The use of the prefix _ for the synthesized storage property name is deliberate: it provides a predictable name for the synthesized storage property that fits established conventions for private stored properties.

[...]

§ A property wrapper type can choose to provide a projection property (e.g., $foo) to expose more API for each wrapped property by defining a projectedValue property.
As with the wrappedValue property and init(wrappedValue:), the projectedValue property must have the same access level as its property wrapper type.

As property wrappers are new to Swift as a whole, documentation is still lacking on Apple's side in my opinion, especially when it comes to SwiftUI.
However, there are only a handful of property wrappers we really have to know about (@State, @Binding, @EnvironmentObject, @ObservedObject, @Published) to fully utilise SwiftUI; all other aspects of SwiftUI (such as View types) are pretty well documented in Apple's Developer docs.

Additionally, articles shared in the Swift community (example) can help you to get a grasp on where you might want to implement property wrappers yourself!

Is there a list of absolutely EVERY modifier that is available for SwiftUI?

The easiest way to find the list of all the modifiers in the Xcode search by searching View Modifiers. The Xcode then gives you this list: Link to the Apple ViewModifiers documentation

I think this is the best we can do with standard modifiers. Also, keep in mind, that there are could be more of them in a project that you work on as anyone can add new modifiers to their projects.



Related Topics



Leave a reply



Submit