9

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

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

1 Answer 1

3

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 } 
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't onAppear() same as viewDidAppear() not viewWillAppear()?
@jonye._.jin No, onAppear is called when a view is inserted into view hierarchy - it might be far away from appearing on screen, if ever at all.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.