Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewWillAppear(_:) viewDidDisappear(_:) View SwiftUI

Tags:

ios

swiftui

I want to fetch the data from on viewWillAppear(_:)

Is there any equal method or modifier available in SwiftUI also any modifier for viewDidDisappear(_:)

like image 445
Kishore Suthar Avatar asked Nov 24 '19 05:11

Kishore Suthar


1 Answers

Sure there are

@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

}
like image 79
Asperi Avatar answered Oct 21 '22 12:10

Asperi