stuchlej
(Mikoláš Stuchlík)
1
Hello,
I was wondering if anybody could explain what kind of closure is second argument of UIView. animate(withDuration:animations:). Is it a standard closure or is it more like some kind of "function builder" under the hood?
Thanks :)
toph42
(Topher Hickman)
2
According to the documentation, it’s just a regular Void returning closure where you make the changes to the view.
Here’s a tutorial that might help you: Basic UIView Animation Tutorial: Getting Started | Kodeco
To my knowledge, function builder are only used in in SwiftUI, at least for now. There are no function builders in UIKit yet.
stuchlej
(Mikoláš Stuchlík)
4
@toph42 @DevAndArtist
Sorry for my late reply.
I was confused due to my lack of knowledge of iOS API before iOS 8. It appears there are methods beginAnimations:context: and commitAnimations which (imo) worked similarly (for API user) like UITableView's beginUpdates and endUpdates.
Thanks for your replies :)
Lantua
5
You can also look at the signature
animate(withDuration duration: TimeInterval,
animations: @escaping () -> Void)
animations: @escaping () -> Void is non-builder escaping.
In contrast with VStack.init
init(alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content)
@ViewBuilder content: () -> Content is a non-escaping function with ViewBuilder as the function builder.
stuchlej
(Mikoláš Stuchlík)
6
Thank you :) , I am aware that this method is not an instance of Function Builder and that the method is available in Objective-C with a block argument.
By asking
Is it a standard closure or is it more like some kind of "function builder" under the hood?
I meant, whether this method has some unpublished compiler support which goes beyond of types and tools present in swift. Much like swift is able to pass String to UnsafePointer with use of under the hood "magic".