Enum in swift

https://appventure.me/2015/10/17/advanced-practical-enum-examples/ http://brettbukowski.github.io/SwiftExamples/examples/enums/ Basics When creating an enum for use, make sure you declare public. Whatever name labels you declare do not implicitly map to values. Rather, they are their own values. When a variable is assigned to an enum’s member, and gets printed, it will literally print the the enum member.

Say we assign […]

Throwing Errors in swift 3

ref – http://www.techotopia.com/index.php/Understanding_Error_Handling_in_Swift_2 In Swift, errors are represented by values of types that conform to the Error protocol. This empty protocol indicates that a type can be used for error handling. Representing and Throwing Errors In Swift, errors are represented by values of types that conform to the Error protocol. This empty protocol indicates that […]

External and local names

https://useyourloaf.com/blog/swift-named-parameters/ Local parameter names are used in the body of the function/method External parameter names are used when calling the function/method. The external names for all except the first parameter default to the local name

When we call myFunc, we’d do it like:

As you can see, when calling the function, we use […]

Optional Binding

The constant variable songName is non-optional. It is valid only in the if block iff favoriteSong has valid data. The non-optional songName cannot be used elsewhere.

Typealias in swift

http://artsy.github.io/blog/2016/06/24/typealias-for-great-good/ TODO Developers use typealias to create a new type identifier that’s a synonym for another type. You can use typealias for most any type: classes, enums, structs, tuples, closures, etc.

For example: JWT is basically a base64 encoded string of JSON. Clients don’t need to verify the JWT in order to use them, […]

if optionals are nil, and you do Optional Chaining

Optionals Optionals are variables that have valid data OR nil. For example a Non-optional variable is declared like so, and you must initialize it. If you do not initialize it, and you access it, then you’ll get an error:

But if you declare it as an Optional, then it will display nil

For […]

Assign closure to var

ref – http://stackoverflow.com/questions/36749231/function-produces-expected-type-string-did-you-mean-to-call-it-with There are two ways to assign closure to variable First way, is very forward. You create a variable to be of type closure. This closure, let’s say, takes no parameter, and returns a String. You assign it that variable and define the closure implementation. Then you execute the closure with “()”.

[…]

using weak/unowned self in property closure when there is an init function

ref – http://stackoverflow.com/questions/39560860/uiview-cmdevicemotionhandler-unowned-may-only-be-applied-to-class-and-class-b The line of code you’re on is actually run during the init function. self is not available until after all stored properties are initialized. You’re in the middle of the process. The closure businessCardName we’re defining is in the middle of the init process, and thus, do not exist yet. Solution: Declare […]