Please enable JavaScript.
Coggle requires JavaScript to display documents.
Swift, Captura de Pantalla 2020-07-13 a la(s) 05.18.25, Captura de…
Swift
Concepts
Properties
Property Wrapper
-
@propertyWrapper
-
@property Wrapper name var varName
-
-
-
-
Property Observers
- var name: type = value {
willSet(newValue){}
didSet(oldValue){}}
-
-
Closures
- Similar to blocks and lambdas
- The in keyword indicates that the definition of the closure’s parameters and return type has finished, and the body of the closure is about to begin.
- Are reference types
-
-
-
Shorthand Argument Names
$0, $1, $2
-
-
-
-
Programming Elements
Struct
Share
Vars
-
-
Prefix Keywords
-
static var
(Type property)
Lets
Prefix Keywords
-
static let
(Type property)
Methods (Functions that belongs to a struct or class)
- Are reference types
- func functionName(paramLabel: paramType) -> returnType {functionBody}
func minMax(array: [Int]) -> (min: Int, max: Int) {}
- Can use a self reference to a type property
-
-
-
Variadic Parameter
func funcWithVariadicParameters(numbers: Int...) -> Int{
numbers.reduce(0, +)}
funcWithVariadicParameters(numbers: 1,2,3,4,5,6)
Function Types
(Int, Int) -> Int
() -> Void
In-Out Parameter
func changeArray(arreglo: inout [Int]) -> [Int]
{arreglo = arreglo.map{$0 * $0}}
var numeros =[1,2,3,4,5,6]
changeArray(arreglo: &numeros)
-
Prefix Keywords
-
mutating func
-
static func
(type method)
-
class func
(type method)
-
-
-
Access Control
Internal Access
- Default access level
-
internal(set)
-
-
-
Open Access
- Applies only to classes and class members
-
open
Frameworks
-
SwiftUI
-
Structures
-
Container Views
-
-
HStack<Content> (alignment: VerticalAlignment = .center, spacing: CGFloat? = nil, content: () -> Content) where Content : View
-
-
-
RoundedRectangle(cornerRadius: CGFloat-CGSize, style: RoundedCornerStyle = .circular)
-
ForEach(Range<Int>, content: (Int) -> Content)
-
-
GeometryReader
<Content> where Content : View
- It contains a GeometryProxy
GeometryProxy
- We usually call it
geometry
Instance Properties
.safeAreaInsets
: EdgeInsets
-
.bottom
-
.leading
-
.top
-
.trailing
Instance Method
.frame
(in coordinateSpace: CoordinateSpace) -> CGRect
- CoordinateSpace is an enumeration
-
.global
-
.local
-
.named
(AnyHashable)
-
Property wrappers
ObservedObject
@ propertyWrapper @ frozen struct ObservedObject<ObjectType> where ObjectType : ObservableObject
-
-
-
AnimatablePair<First, Second> where First : VectorArithmetic, Second : VectorArithmetic
A pair of animatable values, which is itself animatable.
-
Circle
- A circle centered on the frame of the view containing it.
- The circle’s radius equals half the length of the frame rectangle’s smallest edge.
-
Core Graphics
Structures
CGSize(width: <CGFloat-Double-Int>, height: <CGFloat-Double-Int>)
A structure that contains width and height values.
-
-
-
-
-
Swift Standard Library
-
Generic Functions
min
<T>( x: T, y: T) -> T where T : Comparable
- Returns the lesser of x and y. If x is equal to y, returns x.
Combine
Protocols
ObservableObject
- Only works for classes
- Its adds the property objectWillChange
-
-
-
-
-
-
-
-
-
-