Array implementation of append knows nothing about the argument and it does not care. Element is not any known struct or class of protocol, it is just a placeholder.
CLOSURES:
It is so commin to pass functions around that we are very often in lining them.
We call such an inclined function a closure and there is a special language to support for it.
almost every function or var used inside classes should be marked as private or private(set)
@ViewBuilder
ViewBuilder is used extensively in SwiftUI to let you create new on-screen views by just listing them out in a trailing closure
It's a property wrapper applied to function parameter
extensionArray{varoneAndOnly:Element?{
if self.count ==1{returnself.first
}else{returnnil}}
@escaping
@escaping is used to inform callers of a function that takes a closure that the closure might be stored or otherwise outlive the scope of the receiving function
whenever you have a function that you are passing that escapes. mark it @escaping. We are holding onto the function.
extensionArray{varoneAndOnly:Element?{
if self.count ==1{returnself.first
}else{returnnil}}
Day 4(Lectures 6-8)
Implicit Aninamtions
.animation(Animation)
Automatic animation
All view modifiers that precede this call will be animated
structCardify:AnimatableModifier{varisFacedUp:BoolvarisMatched:Boolvarrotation:Double//rotation in degreesvaranimatableData:Double{get{rotation}set{rotation = newValue}}
matchedGeometryEffect and @NameSpace
Sometimes you want a view to move from one place of the screen to another
If the view is moving to a new place in its same container, this is no problem
Moving like this is just animating the .position ViewModifier arguments
This kind of thing happens automatically when you explicitly animate
struct EmojiMemoryGameView:View{@ObservedObjectvargame:emojiMemoryGame@NamespaceprivatevardealingNameSpace
ForEach(game.cards.filter(isUndealt)){ card in
cardView(card: card).matchedGeometryEffect(id:card.id, in:dealingNameSpace).transition(AnyTransition.asymmetric(insertion:.opacity, removal:.identity)).zIndex(zIndex(of:card))}
Using onAppear for geometry
use when you want to animate a view when it first appears on screen use .onAppar.