Please enable JavaScript.
Coggle requires JavaScript to display documents.
swift (lang (class / struct (Protocols (Initializer (required init), Class…
swift
lang
-
-
String
-
-
value type, copy-on-write
-
-
function
-
-
-
-
in-out parameter
func swapTwoInts(_ a: inout Int, _ b: inout Int) {}
swapTwoInts(&someInt, &anotherInt)
-
In-out parameters cannot have default values, and variadic parameters cannot be marked as inout.
closure
-
three forms
-
Nested functions are closures that have a name and can capture values from their enclosing function.
Closure expressions are unnamed closures written in a lightweight syntax that can capture values from their surrounding context.
Syntax
{ (s1: String, s2: String) -> Bool in return s1 > s2 }
{ s1, s2 in return s1 > s2 }
-
-
-
-
-
enumeration
-
enum Barcode { case upc(Int, Int, Int, Int); case qrCode(String) }
-
-
-
-
-
-
generic
-
type parameter
func swapTwoValues<T>(_ a: inout T, _ b: inout T) {}
type constraint
func someFunction<T: SomeClass, U: SomeProtocol>(someT: T, someU: U) {}
func allItemsMatch<C1: Container, C2: Container> (_ someContainer: C1, _ anotherContainer: C2) -> Bool where C1.Item == C2.Item, C1.Item: Equatable {}
class / struct
Structures are always copied when they are passed around in your code, and do not use reference counting.
-
-
-
Initialization
For class instances, a constant property can be modified during initialization only by the class that introduces it. It cannot be modified by a subclass.
-
-
-
-
Subclasses can modify inherited variable properties during initialization, but can not modify inherited constant properties.
-
-
Extensions
Extensions add new functionality to an existing class, structure, enumeration, or protocol type.
Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties.
Extensions can add new functionality to a type, but they cannot override existing functionality.
-
Protocols
-
-
-
-
Types do not automatically adopt a protocol just by satisfying its requirements. They must always explicitly declare their adoption of the protocol.
-
-
-
-
-
-
-
-
-
-