A dive into Swift 2

Here are some of my notes when diving into Swift

Default parameter reorder

If a function arguments have default values, you can reorder them at call site.

Note that the first parameter `num1` must have external name

Tuple shuffle

Be careful with generic

Here is when I’m trying to do a [Resolver](https://github.com/onmyway133/Resolver)

Here I mistakenly use it, because generic can accept any type, even closure

And now `factory.dynamicType` is of type `() -> () -> String`, not what I expect `() -> String`

Short notation works for any static member

- [Help Yourself to Some Swift](http://bandes-stor.ch/blog/2015/11/28/help-yourself-to-some-swift/)

We can also `.init` because the type of the property is already specified

Resolving generic type

Supposed we have contrived method like this, which does not accept any parameter

We can use `as` to resolve the type, or specify the type

You can learn more when reading [Dip](https://github.com/AliSoftware/Dip)

Reference instance method

- [Instance Methods are Curried Functions in Swift](http://oleb.net/blog/2014/07/swift-instance-methods-curried-functions/)

Supposed we have

We can make a reference to that instance method

We can see that `ref` is of type `Cat -> () -> ()`


- [Swift asserts — the missing manual](http://blog.krzyzanowskim.com/2015/03/09/swift-asserts-the-missing-manual/)

Check for a condition, works even in release mode.


- [Data Type Size Calculation](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-ID185)
- [http://chris.eidhof.nl/posts/swift-c-interop.html](http://chris.eidhof.nl/posts/swift-c-interop.html)

> In C, the sizeof operator returns the size of any variable or data type. In Swift, you use the sizeof function to get the size of a given type, or the sizeofValue function to get the size of the type of a given value

Arguments are tuple

- [Tuple as Function arguments](https://medium.com/swift-programming/tuple-as-function-argument-619523b6e06b#.n05z7mpbw)

- Tuple elements must be the same number, of the same types, and have the same external parameter name as in function