我想从viewWillAppear(_:)
上获取数据
SwiftUI
中是否有任何相等的方法或修饰符可用 还有viewDidDisappear(_:)
的任何修饰符
当然有
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) extension View { /// Adds an action to perform when this view appears. /// /// - Parameter action: The action to perform. If `action` is `nil`, the /// call has no effect. /// - Returns: A view that triggers `action` when this view appears. @inlinable public func onAppear(perform action: (() -> Void)? = nil) -> some View /// Adds an action to perform when this view disappears. /// /// - Parameter action: The action to perform. If `action` is `nil`, the /// call has no effect. /// - Returns: A view that triggers `action` when this view disappears. @inlinable public func onDisappear(perform action: (() -> Void)? = nil) -> some View }